set_subgrid() *

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

  • Parameter(s):
    • $obj_grid: phpGrid object as subgrid
    • $s_fkey: subgrid foreign key.
    • $m_fkey: Optional. Master foreign key. (ver 4.5+).
  • Description:
    • The method displays inline and read-only detail grid rather than in separate datagrid table. It is similar to set_masterdetail() except it can takes an additional parameter as the foreign key from master grid. When ignored, phpGrid assumes that m_fkey has the same value as the s_fkey.
  • 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 an different alias as table name in the select statement.
    • 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();

No related content found.

Tags: