@ AuthorYHC uses the datagrid detailed view. You can expand a row to display an additional detailed information. Any class capacity can be loaded as row details, and subgrid can also be dynamically loaded. this tutorial will show you how to create a subgrid on the primary grid. view Demo steps... syntaxHighlight
@ Author YHC
Using the datagrid Details View, you can expand a row to display an additional detailed information. Any class capacity can be loaded as row details, and subgrid can also be dynamically loaded. this tutorial will show you how to create a subgrid on the primary grid.
View Demo
Step 1: Create a primary DataGrid
[Html]
Item ID |
Product ID |
List Price |
Unit Cost |
Attribute |
Status |
Item ID |
Product ID |
List Price |
Unit Cost |
Attribute |
Status |
Step 2: Set the detailed view to display the subgrid
When using the detailed view, remember to introduce the header of the view script js file on your page.
[Html]
[Javascript] view plaincopyprint? $ ('# Dg'). datagrid ({
View: detailview,
DetailFormatter: function (index, row ){
Return'
';
},
OnExpandRow: function (index, row ){
$ ('# Ddv-' + index). datagrid ({
Url: 'maid _ getdetail. php? Itemid = '+ row. itemid,
FitColumns: true,
SingleSelect: true,
Rownumbers: true,
LoadMsg :'',
Height: 'auto ',
Columns :[[
{Field: 'orderid', title: 'order id', width: 100 },
{Field: 'quantity ', title: 'quantity', width: 100 },
{Field: 'unitprice', title: 'unit price', width: 100}
],
OnResize: function (){
$ ('# Dg'). datagrid ('fixdetailrowheight', index );
},
OnLoadSuccess: function (){
SetTimeout (function (){
$ ('# Dg'). datagrid ('fixdetailrowheight', index );
}, 0 );
}
});
$ ('# Dg'). datagrid ('fixdetailrowheight', index );
}
});
$ ('# Dg'). datagrid ({
View: detailview,
DetailFormatter: function (index, row ){
Return'
';
},
OnExpandRow: function (index, row ){
$ ('# Ddv-' + index). datagrid ({
Url: 'maid _ getdetail. php? Itemid = '+ row. itemid,
FitColumns: true,
SingleSelect: true,
Rownumbers: true,
LoadMsg :'',
Height: 'auto ',
Columns :[[
{Field: 'orderid', title: 'order id', width: 100 },
{Field: 'quantity ', title: 'quantity', width: 100 },
{Field: 'unitprice', title: 'unit price', width: 100}
],
OnResize: function (){
$ ('# Dg'). datagrid ('fixdetailrowheight', index );
},
OnLoadSuccess: function (){
SetTimeout (function (){
$ ('# Dg'). datagrid ('fixdetailrowheight', index );
}, 0 );
}
});
$ ('# Dg'). datagrid ('fixdetailrowheight', index );
}
}); When you click the expand button ('+'), The onExpandRow event will be triggered. We will create a new sub-grid and three columns. Remember to call the fixDetailRowHeight method for the primary grid, when the sub-grid data is loaded successfully
Then change the size.
Step 3: server code
Datagrid22_getdata.php
[Php]
$ Result = array ();
Include 'conn. php ';
$ Rs = mysql_query ("select * from item where itemid in (select itemid from lineitem )");
$ Items = array ();
While ($ row = mysql_fetch_object ($ rs )){
Array_push ($ items, $ row );
}
Echo json_encode ($ items );
$ Result = array ();
Include 'conn. php ';
$ Rs = mysql_query ("select * from item where itemid in (select itemid from lineitem )");
$ Items = array ();
While ($ row = mysql_fetch_object ($ rs )){
Array_push ($ items, $ row );
}
Echo json_encode ($ items); datagrid22_getdetail.php
[Php]
$ Itemid = $ _ REQUEST ['itemid'];
Include 'conn. php ';
$ Rs = mysql_query ("select * from lineitem where itemid = '$ itemid '");
$ Items = array ();
While ($ row = mysql_fetch_object ($ rs )){
Array_push ($ items, $ row );
}
Echo json_encode ($ items );
$ Itemid = $ _ REQUEST ['itemid'];
Include 'conn. php ';
$ Rs = mysql_query ("select * from lineitem where itemid = '$ itemid '");
$ Items = array ();
While ($ row = mysql_fetch_object ($ rs )){
Array_push ($ items, $ row );
}
Echo json_encode ($ items );
Author: yhc13429826359