Master Detail Archives | phpGrid - PHP Datagrid Create PHP grids in minutes, not hours. Tue, 03 Dec 2024 22:55:10 +0000 en-US hourly 1 CodeProjecthttps://wordpress.org/?v=7.0.3 129966043 Change Master Detail Grids Layout Using CSS https://phpgrid.com/example/change-master-detail-grids-layout-using-css/ Sun, 24 Feb 2019 21:55:50 +0000 http://phpgrid.com/?p=9506

The default master detail grid has the top down layout. The master, the parent datagrid is always on top of the child grid. This is the default layout. Each datagrid is enclosed by a div with a unique ID. In the example below, the master grid would have the ID gbox_orders, and the 1st detail […]

The post Change Master Detail Grids Layout Using CSS appeared first on phpGrid - PHP Datagrid.

]]>

The default master detail grid has the top down layout. The master, the parent datagrid is always on top of the child grid. This is the default layout. Each datagrid is enclosed by a div with a unique ID.

In the example below, the master grid would have the ID gbox_orders, and the 1st detail grid would have the ID gbox_orders_d1 (Replace “orders” here with your own master table name) Once you have those IDs, one can use CSS to set layout easily. Read more about CSS layout on w3school.

The below CSS set the parent grid float on the left while the child grid is fixed at the right bottom corner.

1
2
3
4
5
6
7
8
9
10
11
12
/*; master grid id format: #gbox_<MASTER TABLE NAME> */
#gbox_orders{
    float:left;
    margin:30px 10px;
}
/* detail grid id format: #gbox_<MASTER TABLE NAME>_d<index> */
#gbox_orders_d1{
    margin:10px;
    position: fixed;
    bottom: 0;
    right: 0;
}

Live Demo!

The post Change Master Detail Grids Layout Using CSS appeared first on phpGrid - PHP Datagrid.

]]>
9506
Nested Master Detail Datagrid * https://phpgrid.com/example/nested-master-detail-datagrid/ Mon, 21 Feb 2011 00:02:13 +0000 http://phpgrid.com/?p=1157 * Please note this feature is only available in Premium and higher editions. The master detail datagrid can be nested to show relationships for multilevel hierarchal data. The example shows only three levels, though the number of nested levels can be unlimited. 123456789101112131415161718192021// Always include namespace and conf.php on TOP of the script. use phpCtrl\C_DataGrid; […]

The post Nested Master Detail Datagrid * appeared first on phpGrid - PHP Datagrid.

]]>
* Please note this feature is only available in Premium and higher editions.

The master detail datagrid can be nested to show relationships for multilevel hierarchal data. The example shows only three levels, though the number of nested levels can be unlimited.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
// Always include namespace and conf.php on TOP of the script.
use phpCtrl\C_DataGrid;
require_once("/file/path/to/conf.php");  

//suppliers master-detail
$sg = new C_DataGrid("SELECT * FROM suppliers","supplierCode","suppliers");
$sg -> set_sql_key("supplierName");

//supplier detail2: products
$sg_d1 = new C_DataGrid("SELECT productCode,productName,productDescription,quantityInStock,MSRP,productVendor FROM products","productCode","products");

//nested grid-level 3 for products
$sg_d1_n1 = new C_DataGrid("SELECT * FROM productparts","productCode","productparts");

//set detail for products
$sg_d1 -> set_masterdetail($sg_d1_n1, 'productCode');

//set detail 2 for suppliers
$sg -> set_masterdetail($sg_d1, 'productVendor');

$sg -> display();

Note:
In the demo, click on #3 in suppliers grid first.

 
See Live Example! (In the demo, click on #3 in suppliers grid)

The post Nested Master Detail Datagrid * appeared first on phpGrid - PHP Datagrid.

]]>
1157
Master with Multiple Detail Grids * https://phpgrid.com/example/masterdetail-master-grid-with-multiple-detail-grids/ Fri, 11 Feb 2011 01:54:06 +0000 http://phpgrid.com/?p=1139 * Please note this feature is only available in paid versions. phpGrid supports a master grid with multiple detail grids. There is no limit on how many detail grids a master datagrid can have. Detail grids are defined the way as the master datagrid does. Click on example link to see it in action! Note […]

The post Master with Multiple Detail Grids * appeared first on phpGrid - PHP Datagrid.

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

phpGrid supports a master grid with multiple detail grids. There is no limit on how many detail grids a master datagrid can have. Detail grids are defined the way as the master datagrid does. Click on example link to see it in action!

Note that you can have master and detail grids from the same database table as long as different SQL alias are used.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
// Always include namespace and conf.php on TOP of the script.
use phpCtrl\C_DataGrid;
require_once("/file/path/to/conf.php");  

//suppliers master-detail
$sg = new C_DataGrid("SELECT * FROM suppliers","supplierCode","suppliers");
$sg->set_sql_key("supplierName");
 
//supplier detail 1: product lines
$sg_d1 = new C_DataGrid("SELECT * FROM supplierproductlines","supplierCode","supplierproductlines");
 
$sg->set_masterdetail($sg_d1, 'supplierName');
 
//supplier detail2: products
$sg_d2 = new C_DataGrid("SELECT productCode,productName,productDescription,quantityInStock,MSRP,productVendor FROM products","productCode","products");
 
//set detail 2 for suppliers
$sg->set_masterdetail($sg_d2, 'productVendor');
$sg->display();

See Live Example!

The post Master with Multiple Detail Grids * appeared first on phpGrid - PHP Datagrid.

]]>
1139
Subgrid * https://phpgrid.com/example/subgrid/ Fri, 17 Sep 2010 04:43:35 +0000 http://64.38.236.7/?p=561     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. 12345678910111213141516171819202122// Always include […]

The post Subgrid * appeared first on phpGrid - PHP Datagrid.

]]>
subgrid multilevel

 
 

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.

Starting version 6, nested, drill-down subgrids are supported!
X
Due to the calling sequence, the enable_edit() should be called BEFORE set_subgrid() method, or edit properties will be ignored.
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();

See 3-Level Nested Subgrid Example!

The post Subgrid * appeared first on phpGrid - PHP Datagrid.

]]>
561
Master Detail with Column Alias https://phpgrid.com/example/master-detail-with-column-alias/ Fri, 17 Sep 2010 04:41:23 +0000 http://phpgrid.com/?p=2860 It can be tricky working with master detail grids with column name alias, especially during edit. Using our sample database, here’s a working snippet. 1234567891011use phpCtrl\C_DataGrid; require_once("/file/path/to/conf.php");   $sg = new C_DataGrid("SELECT employeeNumber, employeeNumber as salesRepEmployeeNumber, lastName, firstName, email, jobTitle FROM  employees","employeeNumber","employees"); $sg_d1 = new C_DataGrid("SELECT customerNumber, customerName, city, state, salesRepEmployeeNumber, phone FROM customers","customerNumber","customers"); $sg […]

The post Master Detail with Column Alias appeared first on phpGrid - PHP Datagrid.

]]>
It can be tricky working with master detail grids with column name alias, especially during edit. Using our sample database, here’s a working snippet.

1
2
3
4
5
6
7
8
9
10
11
use phpCtrl\C_DataGrid;
require_once("/file/path/to/conf.php");  

$sg = new C_DataGrid("SELECT employeeNumber, employeeNumber as salesRepEmployeeNumber, lastName, firstName, email, jobTitle FROM  employees","employeeNumber","employees");
$sg_d1 = new C_DataGrid("SELECT customerNumber, customerName, city, state, salesRepEmployeeNumber, phone FROM customers","customerNumber","customers");

$sg -> set_masterdetail($sg_d1, 'salesRepEmployeeNumber');
$sg -> enable_edit()->set_col_readonly("salesRepEmployeeNumber");
$sg_d1 -> enable_edit();

$sg -> display();

In master table “employeeNumber” is the FK reference to the detail table that has the column named “salesRepEmployeeNumber”. Create an alias that matches the corresponding name used in detail table, in this case it’s “salesRepEmployeeNumber”; it’s important to also keep the original column name because in some database such as MySQL does not allow alias in WHERE clause.

Lastly, use set_col_readonly() to set the alias name “salesRepEmployeeNumber” to read only so it won’t be passed to database for editing.

The only limitation is that the SQL alias must be in master grid, or the edit will again fail.

See Live Example!

Also available on KB: http://phpgrid.uservoice.com/knowledgebase/articles/411029

The post Master Detail with Column Alias appeared first on phpGrid - PHP Datagrid.

]]>
2860
Master Detail Grid * https://phpgrid.com/example/master-detail-grid/ Fri, 17 Sep 2010 04:40:01 +0000 http://64.38.236.7/?p=556 * Please note this feature is only available in Premium and higher editions. The phpGrid went extra miles to make creating the master detail datagrid a super simple task. There is essentially a simple function to set_masterdetail() to set the master detail relationship between two datagrids, and have them work interactively. The detail grid is […]

The post Master Detail Grid * appeared first on phpGrid - PHP Datagrid.

]]>
* Please note this feature is only available in Premium and higher editions.

The phpGrid went extra miles to make creating the master detail datagrid a super simple task. There is essentially a simple function to set_masterdetail() to set the master detail relationship between two datagrids, and have them work interactively.

The detail grid is a regular phpGrid object and can have the same methods like any other datagrid, such as description title, sort, and update etc. The detail grid renders dynamically based on the row selected in parent grid. A master grid can have one detail grid one or more detail datagrids.

Note that you can have master and detail grids from the same database table as long as different SQL alias are used.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// 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");

// change column titles
$dg->set_col_title("orderNumber", "Order No.");
$dg->set_col_title("orderDate", "Order Date");
$dg->set_col_title("shippedDate", "Shipped Date");
$dg->set_col_title("customerNumber", "Customer No.");
 
// enable edit
$dg->enable_edit("INLINE", "CRUD");

// hide a column
$dg -> set_col_hidden("requiredDate");

// read only columns, one or more columns delimited by comma
$dg -> set_col_readonly("orderDate, customerNumber");

// required fields
$dg -> set_col_required("orderNumber, customerNumber");

// multiple select
$dg -> set_multiselect(true);
 
// second grid as detail grid. Notice it is just another regular phpGrid with properites.
$sdg = new C_DataGrid("SELECT orderNumber,productCode,quantityOrdered,priceEach FROM OrderDetails", "orderNumber", "OrderDetails");
$sdg->set_col_title("orderNumber", "Order No.");
$sdg->set_col_title("productCode", "Product Code");
$sdg->set_col_title("quantityOrdered", "Quantity");
$sdg->set_col_title("priceEach", "Unit Price");
$sdg->set_col_dynalink("productCode", "http://www.example.com/", "orderLineNumber", '&foo');
$sdg->set_col_format('orderNumber','integer', array('thousandsSeparator'=>'','defaultValue'=>''));
$sdg->set_col_currency('priceEach','$');

// define master detail relationship by passing the detail grid object as the first parameter, then the foriegn key name.
$dg->set_masterdetail($sdg, 'orderNumber');

$dg->display();

See Live Example!


Common Issue:
Missing add icon in the detail grid

The post Master Detail Grid * appeared first on phpGrid - PHP Datagrid.

]]>
556