@ Author YHC
The datagrid can change its view to display different effects. using the Details View, the datagrid can display the expand button ("+" or "-") on the left of the Data row. You can expand a row to display an additional details.
View Demo
Step 1: Create a DataGrid
[Html]
<Table id = "dg" style = "width: 500px; height: 250px "url =" data/datagrid_data.json "title =" DataGrid-Expand Row "singleselect =" true "fitcolumns =" true ">
<Thead>
<Tr>
<Th field = "itemid" width = "60"> Item ID </th>
<Th field = "productid" width = "80"> Product ID </th>
<Th field = "listprice" align = "right" width = "70"> List Price </th>
<Th field = "unitcost" align = "right" width = "70"> Unit Cost </th>
<Th field = "status" width = "50" align = "center"> Status </th>
</Tr>
</Thead>
</Table>
<Table id = "dg" style = "width: 500px; height: 250px "url =" data/datagrid_data.json "title =" DataGrid-Expand Row "singleselect =" true "fitcolumns =" true ">
<Thead>
<Tr>
<Th field = "itemid" width = "60"> Item ID </th>
<Th field = "productid" width = "80"> Product ID </th>
<Th field = "listprice" align = "right" width = "70"> List Price </th>
<Th field = "unitcost" align = "right" width = "70"> Unit Cost </th>
<Th field = "status" width = "50" align = "center"> Status </th>
</Tr>
</Thead>
</Table> Step 2: Set a detailed view for the DataGrid
When using the detailed view, remember to introduce the header of the View script 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 id = "ddv-' + index + '" style = "padding: 5 p x 0"> </div> ';
},
OnExpandRow: function (index, row ){
$ ('# Ddv-' + index). panel ({
Border: false,
Cache: false,
Href: 'maid _ getdetail. php? Itemid = '+ row. itemid,
OnLoad: function (){
$ ('# Dg'). datagrid ('fixdetailrowheight', index );
}
});
$ ('# Dg'). datagrid ('fixdetailrowheight', index );
}
});
$ ('# Dg'). datagrid ({
View: detailview,
DetailFormatter: function (index, row ){
Return '<div id = "ddv-' + index + '" style = "padding: 5 p x 0"> </div> ';
},
OnExpandRow: function (index, row ){
$ ('# Ddv-' + index). panel ({
Border: false,
Cache: false,
Href: 'maid _ getdetail. php? Itemid = '+ row. itemid,
OnLoad: function (){
$ ('# Dg'). datagrid ('fixdetailrowheight', index );
}
});
$ ('# Dg'). datagrid ('fixdetailrowheight', index );
}
}); We define the detailFormatter function to tell the datagrid how to render the detailed view. In this case, we return a simple '<div>' element, it will act as the most detailed container,
Note: The details are empty. When you click the expand button ('+'), The onExpandRow event will be triggered, so we can write some code to load the ajax details, finally, we call the fixDetailRowHeight method to fix the Row Height. After the detailed content is loaded.
Step 3: server code
Datagrid21_getdetail.php
[Php]
<? Php
$ Itemid = $ _ REQUEST ['itemid'];
$ Content = file_get_contents ('data/datagrid_data.json ');
$ Data = json_decode ($ content, true );
Foreach ($ data ['rows '] as $ item ){
If ($ item ['itemid'] = $ itemid ){
Break;
}
}
?>
<Table class = "dv-table" border = "0" style = "width: 100%;">
<Tr>
<Td rowspan = "3" style = "width: 60px">
<? Php
Echo " ";
?>
</Td>
<Td class = "dv-label"> Item ID: </td>
<Td> <? Php echo $ item ['itemid'];?> </Td>
<Td class = "dv-label"> Product ID: </td>
<Td> <? Php echo $ item ['produtid'];?> </Td>
</Tr>
<Tr>
<Td class = "dv-label"> List Price: </td>
<Td> <? Php echo $ item ['listprice'];?> </Td>
<Td class = "dv-label"> Unit Cost: </td>
<Td> <? Php echo $ item ['unitcost'];?> </Td>
</Tr>
<Tr>
<Td class = "dv-label"> Attribute: </td>
<Td colspan = "3"> <? Php echo $ item ['attr1'];?> </Td>
</Tr>
</Table>
Author: yhc13429826359