Latest web development tutorials
×

jQuery EasyUI Tutorial

jQuery EasyUI Tutorial jQuery EasyUI Introduction

jEasyUI application

jEasyUI Create a CRUD application jEasyUI Create a CRUD data grid jEasyUI Form CRUD application jEasyUI Create an RSS reader

jEasyUI Drag and drop

jEasyUI Basic drag and drop jEasyUI Create a drag-and-drop shopping cart jEasyUI Create a school curriculum

jEasyUI Menus and buttons

jEasyUI Create a simple menu jEasyUI Create a link button jEasyUI Create a menu button jEasyUI Create a split button

jEasyUI layout

jEasyUI Create a border layout jEasyUI Create a complex layout jEasyUI Creates a fold panel jEasyUI Create a tab page jEasyUI Dynamically add a tab jEasyUI Add the AutoPlay tab jEasyUI Create the XP style left panel

jEasyUI Data grid

jEasyUI Convert HTML tables to data grids jEasyUI Get the selected row data jEasyUI Add the query function jEasyUI Add a toolbar jEasyUI Create complex toolbars jEasyUI Sets the frozen column jEasyUI Dynamically change columns jEasyUI Format the column jEasyUI Set sort jEasyUI Custom sorting jEasyUI Create a column combination jEasyUI Add a check box jEasyUI Custom tab jEasyUI Enable in-line editing jEasyUI Extension editor jEasyUI Column operation jEasyUI Merge Cells jEasyUI Create a custom view jEasyUI Create a footer summary jEasyUI Condition Sets the line background color jEasyUI Create an attribute grid jEasyUI The extended line shows the details jEasyUI Create a subgrid jEasyUI Display massive data jEasyUI Add a paging component

jEasyUI window

jEasyUI Create a simple window jEasyUI Customize the Window Toolbar jEasyUI Window and layout jEasyUI Create a dialog box jEasyUI Customize the dialog box

jEasyUI Tree menu

jEasyUI Use the markup to create a tree menu jEasyUI Create an asynchronous tree menu jEasyUI Tree menu to add nodes jEasyUI Create a tree menu with check boxes jEasyUI Tree menu drag and drop control jEasyUI The Tree menu loads the parent / child nodes jEasyUI Create the base tree grid jEasyUI Create a complex tree grid jEasyUI Dynamic loading of tree jEasyUI The tree grid adds pagination jEasyUI Tree-lazy lazy-loading node

jEasyUI Form

jEasyUI Create an asynchronous submission form jEasyUI Form validation jEasyUI Create a tree drop-down box jEasyUI Format the drop-down box jEasyUI Filter down the data grid

jEasyUI Reference Manual

jQuery EasyUI Plugin jQuery EasyUI Extended

jQuery EasyUI Data Grid - Creating Subdivisions

Details view uses the data grid (datagrid), the user can expand the row to display additional details. Any content can be loaded as a detail row, sub-grid also can be dynamically loaded. This tutorial will show you how to create a sub-grid on the main grid.

Step 1: Create the main grid

<Table id = "dg" style = "width: 700px; height: 250px"
		url = "datagrid22_getdata.php" 
		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>
			<Th field = "attr1" width = "220"> Attribute </ th>
			<Th field = "status" width = "60" align = "center"> Status </ th>
		</ Tr>
	</ Thead>
</ Table>

Step 2: Set to show a detailed view of Subdivisions

In order to use a detailed view, please remember to refer to a view script file in the page header.

<Script type = "text / javascript" src = "http://www.w3cschool.cc/try/jeasyui/datagrid-detailview.js"> </ script>
$ ( '# Dg'). Datagrid ({
	view: detailview,
	detailFormatter: function (index, row) {
		return '<div style = "padding: 2px"> <table class = "ddv"> </ table> </ div>';
	},
	onExpandRow: function (index, row) {
		var ddv = $ (this) .datagrid ( 'getRowDetail', index) .find ( 'table.ddv');
		ddv.datagrid ({
			url: 'datagrid22_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 the user clicks the expand button ( '+'), 'onExpandRow' event will be triggered. We create a new grid with three subnets. When the sub-mesh data when loaded successfully or change the size, please remember to call the main grid 'fixDetailRowHeight' method.

Step 3: The server-side code

datagrid22_getdata.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);
datagrid22_getdetail.php
include 'conn.php';

$ Itemid = mysql_real_escape_string ($ _ REQUEST [ 'itemid']);

$ 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);

Download jQuery EasyUI examples

jeasyui-datagrid-datagrid22.zip