Sometimes, users who have just visited the Master/Detail page of the certain record and back to its Master page, want to know which record in that Master page that he had just visited its detail page quickly. For example, by highlighting that related record in the Master page. This is very important for them so that they won't visit the same detail page again.
Now I will show you step by step how to implement this case study. We will use both Server Events and Client Scripts. This trick is very useful if your users are browsing the records one by one by viewing its detail page, and after they come back to its master page, then they are able to identify quickly which record they had just visited.
In this following example, let's use the PHPMaker demo project which you can download it from the official website of PHPMaker. For simplicity, we will use orders as the Master table, and orderdetails as the Detail table. For further information, please visit the related topic in PHPMaker discussion forum.
[hidepost]
- Run the PHPMaker demo project (.pmp) file using your PHPMaker application.
-
From the Database pane in the left side, please choose/click on orderdetails table, then you will see there are three new tabs appear in the top right pane. Click on Code (Server Events, Client Scripts and Custom Templates) tab, expand the following path: Client Scripts -> Table-Specific -> List Page -> Startup Script, and then insert the following code into the code editor at the right pane:
$(document).ready(function(){ $("a[href='orderslist.php']").attr('href', 'orderslist.php?OrderID=<?php echo isset($_GET["OrderID"])?ew_StripSlashes($_GET["OrderID"]):"" ?>'); });
This code means add the suffix in the Back to master table link with the OrderID as the master key in the current master/detail page.
-
Next step, from the Database pane in the left-side of your PHPMaker, click on orders table, and then expand the following path: Server Events -> Table-Specific -> Common -> Row_Rendered, and then insert the following code into the function:
if (isset($_GET["OrderID"])) { $getMasterKey = ew_StripSlashes($_GET["OrderID"]); if ($this->OrderID->CurrentValue==$getMasterKey) { $this->RowAttrs["style"] = "background-color: #FF6600"; } }
This code means to highlight the row in Master page if its key is equal with the last master/detail key that has just visited.
- Finally, re-generate your script files using PHPMaker as always. Have a nice code!
[/hidepost]
Leave a Reply
You must be logged in to post a comment.