Defining a subgrid is essentially the same as setting up the master detail grid as described in our previous example. Again, only a single line of code change is required by calling set_subgrid(). phpGrid also supports single level with multiple subgrids, similar to master grid that has many detail grids.
X
X
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | // Always include namespace and conf.php on TOP of the script. use phpCtrl\C_DataGrid; require_once("/file/path/to/conf.php"); $dg = new C_DataGrid("SELECT * FROM orders", "orderNumber", "orders"); // enable edit $dg->enable_edit("INLINE", "CRUD"); // second grid as detail grid. Notice it is just another regular phpGrid with properties. $sdg = new C_DataGrid("SELECT * FROM orderdetails", array("orderLineNumber", "productCode"), "orderdetails"); $sdg->enable_edit("INLINE", "CRUD"); // second grid as detail grid. Notice it is just another regular phpGrid with properties. $sdg2 = new C_DataGrid("SELECT * FROM products", array("productCode"), "products"); $sdg2->enable_edit("INLINE", "CRUD"); // define master detail relationship by passing the detail grid object as the first parameter, then the foreign key name. $sdg->set_subgrid($sdg2, 'productCode'); $dg->set_subgrid($sdg, 'orderNumber'); $dg->display(); |