One of the great flexibilities in PHPMaker is the ability to define the different filter for the different pages. This filter is useful whenever you want to limit the records that you want to display. Sometimes you want to show all products in the list of CustomerOrders page, but in the other side, you only want to show the certain products in the Add and or Edit page.
Let's say in the CustomerOrders list page we want to display all of the products name, whereas in the CustomerOrders Add and the CustomerOrders Edit pages, we only want to display the product name which has the Product_Code as the following: "P-001", "P-002", and "P-003". Assuming that the Product field in the CustomerOrders will lookup to the Products table, so that it will display the Product_Name; either in the CustomerOrders List, Add, or Edit page.
If we do not handle this situation by making the different filter, then in the CustomerOrders list page will only display the Product Name that belongs to the three products above, since it will use the filter from the lookup Product field. The products other than the three product items above will be displayed in Product_Code format only. They will not lookup to the Products table because they have been filtered only for displaying the three product items. In other words, we do not want this condition to be happened, thus the lookup should work for either in the List or Add/Edit page; even if the products that will be displayed on them are different.
So here is the recommended trick how you can overcome the issue above by adjusting the Filter from the Field Setup section of PHPMaker application. Simple, yet so powerful. No need to modify the generated scripts!
[hidepost]
Important: In order to facilitate understanding, then we will use the example as described in this article above. Please adjust the related tables/fields with your cases.
- Open your PHPMaker project file (.pmp) using PHPMaker application.
- Click on the Database icon on the toolbar, and then click on the Tables icon in the left side of PHPMaker, until you see the Tables/Views tab in the right pane.
- Click on the CustomerOrders table/view item on the right pane, and then under the General header, you will see there is Filter column. Click on the ... button that related to the CustomerOrders if you want to define the filter which will filter the certain records in the List/Search pages. At the moment, we will leave it empty (although you may define it by yourself) since we want to display all products (there is no filter at this part).
- Click on the CustomerOrders table/view on the left pane, and then click on the Product field. As we mentioned earlier, assuming that this field will lookup to the Products table in order to display the value of Product_Name that belongs to the Products table.
- Next, from the Child lookup fields section in the right bottom of PHPMaker, click on the Filter row, until you see the ... button. Then click on the button at that row, until you see a new window named Filter Editor appears.
-
Type the following code in the Filter Editor:
(CurrentPageID() == "edit" || CurrentPageID() == "add") ? "Product_Code = 'P-001' OR Product_Code = 'P-002' OR Product_Code = 'P-003'" : ""
afterwards click on OK button to save the change and close the Filter Editor window.
That filter code means: If the current page is in the Edit or Add page, then filter the Products records which have the Product_Code only as the following: 'P-001', 'P-002', and 'P-003', otherwise display all products in the other pages (List and Search pages) which do not use the filter (represented by the empty string of filter in that code above).
- Save your project, and then re-generate your .php files as usual using PHPMaker application.
[/hidepost]
Leave a Reply
You must be logged in to post a comment.