Page 1 of 1

Custom Action and Views Table

Posted: Thu May 23, 2024 9:52 pm
by Satrapo

Hello,

I create a view (MySql db) to list some aggregate data (no primary key used in the view) and I generate only the list page for this "View_Table".

In the List Page - Page_Load event I add this simple CustomAction fot testing purpose:

            $this->CustomActions["ActTest2"] = new ListAction(
                "ActTest2",
                "",
                true,
                ACTION_POSTBACK,
                ACTION_SINGLE,
                "Test?",
                "fa-solid fa-right-from-bracket",
                "",
                function($row){
            
                Log("ROW",$row);
                return true;
            },
                "NICE TEST!",
                "ERROR"
            );

It doesn't work, I see the action icon, it ask me to confirm with the popup but then the page reload and nothing is logged and the action icon disappear from the reloaded page. (I've to refresh the page to see it again).

If I use the same code in In the List Page - Page_Load event of other tables (not from views) the code works without issue.

So is not possible use custom action on list page from views?

Thanks!


Re: Custom Action and Views Table

Posted: Thu May 23, 2024 10:46 pm
by mobhar

I have just tested your code in List Page of orders table from demo2024 project, and it actually works properly.

I can see the log from /log/log-2024-05-23.log file as follows:

[2024-05-23T21:43:34.965993+07:00] log.DEBUG: ROW {"OrderID":11082,"CustomerID":"ANATR","EmployeeID":1,"OrderDate":"2024-04-27 00:00:00","RequiredDate":null,"ShippedDate":null,"ShipVia":null,"Freight":0.0,"ShipName":null,"ShipAddress":null,"ShipCity":null,"ShipRegion":null,"ShipPostalCode":null,"ShipCountry":null} []

Re: Custom Action and Views Table

Posted: Thu May 23, 2024 10:52 pm
by Satrapo

mobhar wrote:

I have just tested your code in List Page of orders table from demo2024 project, and it actually works properly.

Is orders table generated form a database view?


Re: Custom Action and Views Table

Posted: Thu May 23, 2024 11:13 pm
by mobhar

Satrapo wrote:

Is orders table generated form a database view?

It is a normal table, not from a database view.


Re: Custom Action and Views Table

Posted: Thu May 23, 2024 11:21 pm
by mobhar

Satrapo wrote:

(no primary key used in the view)

I thinks this is the cause why it won't work. You need to define the primary key for that database view from Fields setup of your PHPMaker project.

As long as the database view has the primary key, then your code should work properly.


Re: Custom Action and Views Table

Posted: Fri May 24, 2024 2:09 am
by Satrapo

You are right!

I'have flagged one field as Primary Key and it works.
However my views has not a real primary key, do you think that this may cause problems in other part of the code? I need only list page for this table, no add or edit page.


Re: Custom Action and Views Table

Posted: Fri May 24, 2024 8:24 am
by mobhar

Satrapo wrote:

However my views has not a real primary key, do you think that this may cause problems in other part of the code?

Exactly.

Even you don't need to generate Add/Edit/View page, you still need to define the primary key for your database view from Fields setup, so that the code in that Page_Load server event that belongs to the List page will work properly.


Re: Custom Action and Views Table

Posted: Fri May 24, 2024 9:24 pm
by Satrapo

Perfect, thank you!