EasyUI creates a child datagrid on the primary datagrid

Source: Internet
Author: User

@ 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]
<Table id = "dg" style = "width: 700px; height: 250px "url =" maid "title =" DataGrid-SubGrid "singleselect =" true "fitcolumns =" true ">
<Thead>
<Tr>
<Th field = "itemid" width = "80"> Item ID </th>
<Th field = "productid" width = "100"> Product ID </th>
<Th field = "listprice" align = "right" width = "80"> List Price </th>
<Th field = "unitcost" align = "right" width = "80"> Unit Cost </th>
& Lt; th field = "attr1" width = "220" & gt; Attribute & lt;/th & gt;
<Th field = "status" width = "60" align = "center"> Status </th>
</Tr>
</Thead>
</Table>

<Table id = "dg" style = "width: 700px; height: 250px "url =" maid "title =" DataGrid-SubGrid "singleselect =" true "fitcolumns =" true ">
<Thead>
<Tr>
<Th field = "itemid" width = "80"> Item ID </th>
<Th field = "productid" width = "100"> Product ID </th>
<Th field = "listprice" align = "right" width = "80"> List Price </th>
<Th field = "unitcost" align = "right" width = "80"> Unit Cost </th>
& Lt; th field = "attr1" width = "220" & gt; Attribute & lt;/th & gt;
<Th field = "status" width = "60" align = "center"> Status </th>
</Tr>
</Thead>
</Table> 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]
<Script type = "text/javascript" src = "http://www.jeasyui.com/easyui/datagrid-detailview.js"> </script>

<Script type = "text/javascript" src = "http://www.jeasyui.com/easyui/datagrid-detailview.js"> </script> [javascript] view plaincopyprint? $ ('# Dg'). datagrid ({
View: detailview,
DetailFormatter: function (index, row ){
Return '<div style = "padding: 2px"> <table id = "ddv-' + index + '"> </table> </div> ';
},
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 '<div style = "padding: 2px"> <table id = "ddv-' + index + '"> </table> </div> ';
},
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
 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.