Simple Subgrid (only for viewing subgrid data) is supported throght the querySubGrid method. The method just outputs the data in format acceptable for the grid.

Related Method(s)
querySubGrid

Related variable(s)
SubgridCommand
dataType

Example:
Again using our example let say that we want to display in subgrid the order details.
For this purpose we need first to enable subGrid with the appropriate parameters and create additional PHP file which will deliver the desired data to the subgrid.

The html file:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>PHP jqGrid Class Example</title> <link rel="stylesheet" type="text/css" media="screen" href="themes/redmond/jquery-ui-1.7.1.custom.css" /> <link rel="stylesheet" type="text/css" media="screen" href="themes/ui.jqgrid.css" /> <script src="js/jquery-1.3.2.min.js" type="text/javascript"></script> <script src="js/i18n/grid.locale-en.js" type="text/javascript"></script> <script src="js/jquery.jqGrid.min.js" type="text/javascript"></script> <script type="text/javascript"> jQuery(document).ready(function(){ .... // Craeate the grid manually jQuery("#grid").jqGrid({ "colModel":[ {"name":"OrderID","index":"OrderID","label":"ID","width":60, "key":true}, {"name":"OrderDate","index":"OrderDate"}, {"name":"CustomerID","index":"CustomerID"}, {"name":"Freight","index":"Freight"}, {"name":"ShipName","index":"ShipName"} ], "url":"querygrid.php", "datatype":"json", "jsonReader":{repeatitems:false}, "pager":"#pager", // changes for the subgrid "subGrid": true, "subGridUrl": "subgrid.php", "subGridModel" : [ { name: ['OrderID', 'ProductID', 'Quantity', 'UnitPrice'], params: ['OrderID'] } ] // end of changes for subgrid }); // Set navigator with search enabled. jQuery("#grid").jqGrid('navGrid','#pager',{add:false,edit:false,del:false}); ...... }); </script> </head> <body> ...... <table id="grid"></table> <div id="pager"></div> ....... </body> </html>

Note that we send additinal parameter OrderID to the SubGrid url in order to identify which order to display.
Let create the new file named subgrid.php with the following content:


<?php require_once 'jq-config.php'; // include the jqGrid Class require_once 'php/jqGrid.php'; // include the driver class require_once 'php/jqGridPdo.php'; // Connection to the server $conn = new PDO(DB_DSN,DB_USER,DB_PASSWORD); // Tell the db that we use utf-8 // Get the needed parameters passed from the main grid $rowid = jqGridUtils::Strip($_REQUEST["OrderID"]); // Create the base jqGrid instance $grid = new jqGrid($conn); // Write the SQL Query $grid->SubgridCommand = "SELECT OrderID, ProductID, Quantity, UnitPrice FROM order_details WHERE orderID=?"; // set the ouput format to json $grid->dataType = 'json'; // Use the build in function for the simple subgrid $grid->querySubGrid(array(&$rowid)); $conn = null; ?>