set_masterdetail() *

* Please note this feature is only available in paid versions.

  • Parameter(s):
    • $obj_grid: phpGrid object as the detail datagrid
    • $fkey: Foreign key to the detail table.
  • Description:
    • This method sets the master detail, or the parent child, relationship between datagrids.
    • The phpGrid went the extra mile to make creating the master detail datagrid a simple task for developers. The primary key value of master datagrid is auomatically retrieved when user selects a row and used as the value to the foreign key in the detail grid. The detail grid renders dynamically based on the row selected in parent grid.
  • Remark:
    • The detail grid is a regular phpGrid object and can have the same methods like any other phpGrid, such as description title, sort, and update etc. A master detail can have one or more detail datagrid. The foreign key, or $fkey, does NOT necessarily have to have the same name as the master table primary key, as long as the same name exists in both master and detail tables.
    • When foreign keys don’t have the same name, you should use SQL alias.
    • Master grid prefills a detail grid with the value of the foreign key during data entry add operation. Version 4.5.5 and above only.
  • Example:
1
2
3
4
// orderId exists in both master table(Orders) and detail table(OrderDetails)
$dg = new C_DataGrid("SELECT orderId, orderDate, customerId FROM Orders", "orderNumber", "Orders");
$sdg = new C_DataGrid("SELECT lineId, orderId, productCode, price FROM OrderDetails", "lineId", "OrderDetails");
$dg -> set_masterdetail($sdg, 'orderId');

When foreign keys don’t have the same name, you can use SQL alias.

1
2
3
4
// productId is SQL alias to productNo in master table(ProductParts), then used as foreign key to link to detail table(Products).
$dg = new C_DataGrid("SELECT partNo, partName, productNo AS productId FROM ProductParts", "partNo", "ProductParts");
$sdg = new C_DataGrid("SELECT productId, productName, productDescription FROM Products", "productId", "Products");
$dg -> set_masterdetail($sdg, 'productId');

Tags:

Top