set_subgrid()

  • Parameter(s):
    • $obj_grid: phpGrid object as subgrid
    • $s_fkey: subgrid foreign key.
    • $m_fkey: Optional. Master foreign key.
  • Description:
    • The method displays inline detail grid rather than in separate datagrid table. It is very similar to set_masterdetail(). When ignored, phpGrid assumes that m_fkey has the same value as the s_fkey.
    •  new The $m_fkey value from the master datagrid is automatically retrieved when a user selects a row.  The value is passed to the pop-up Add form in the subgrid.  ( supported since 7.1.5)
      1
      2
      3
      ...
      $dg->set_subgrid($sdg, 'sales_rep', 'id');
      ...

      subgrid-master-linking-value

  • Remark:
    • Edit is currently not supported in subgrid.
    • Nested subgrid is currently not supported,  Nested/drill-down subgrid is now supported (version 6+).
    • The order of the 2nd and 3rd parameter matters,
    • When the subgrid is the same table(self-reference, in database term) as the master grid, subgrid must use a different table alias in select statement using set_jq_gridName().
    • All the grid properties and method should be called BEFORE set_subgrid is called.
    • Do not include ‘WHERE’ in set_query_filter() when used on subgrid.
    • Due to the calling sequence, the enable_edit() should be called BEFORE set_subgrid() method, or edit properties will be ignored.
  • Example:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
$dg = new C_DataGrid("SELECT * FROM orders", "orderNumber", "orders");
$dg->enable_edit("INLINE", "CRUD");

// 2nd grid as detail grid
$sdg = new C_DataGrid("SELECT * FROM orderdetails", array("orderLineNumber", "productCode"), "orderdetails");
$sdg->enable_edit("INLINE", "CRUD");

// 3rd grid as detail grid.
$sdg2 = new C_DataGrid("SELECT * FROM products", array("productCode"), "products");
$sdg2->enable_edit("INLINE", "CRUD");

// passing the detail grid object as the first parameter, then the foreign key name.
// set_subgrid should be the last method to call before display
$sdg->set_subgrid($sdg2, 'productCode');
$dg->set_subgrid($sdg, 'orderNumber');

$dg->display();