Employees
Orders for the selected Employee

Advanced master detail with editing on detail
Please, take a look at the code.

<?php 
require_once '../../../../php/demo/tabs.php';
?>
<!DOCTYPE html>
<html>
  <head>
    <title>jqGrid PHP Demo</title>
    <link rel="stylesheet" type="text/css" media="screen" href="../../../../css/jquery-ui.css" />
    <link rel="stylesheet" type="text/css" media="screen" href="../../../../css/trirand/ui.jqgrid.css" />
    <link rel="stylesheet" type="text/css" media="screen" href="../../../../css/ui.multiselect.css" />
    <style type="text">
        html, body {
        margin: 0;            /* Remove body margin/padding */
        padding: 0;
        overflow: hidden;    /* Remove scroll bars on browser window */
        font-size: 75%;
        }
        
    </style>
    <script src="../../../../js/jquery.min.js" type="text/javascript"></script>
    <script src="../../../../js/trirand/i18n/grid.locale-en.js" type="text/javascript"></script>
         <script src="../../../../js/trirand/jquery.jqGrid.min.js" type="text/javascript"></script> <script type="text/javascript">         
    $.jgrid.no_legacy_api = true;
    $.jgrid.useJSON = true;
    $.jgrid.defaults.width = "700";
    </script>
     
    <script src="../../../../js/jquery-ui.min.js" type="text/javascript"></script>
  </head>
  <body>
      <div>
          <b>Employees</b>
          <?php include ("grid.php");?>
      </div>
      <div>
          <b>Orders for the selected Employee</b>
          <?php include ("detail.php");?>
      </div>
      <br/>
      <?php tabs(array("grid.php","detail.php"));?>
   </body>
</html>
grid.php.
<?php
require_once '../../jq-config.php';
// include the jqGrid Class
require_once ABSPATH."php/PHPSuito/jqGrid.php";
// include the driver class
require_once ABSPATH."php/PHPSuito/DBdrivers/jqGridPdo.php";
// Connection to the server
$conn = new PDO(DB_DSN,DB_USER,DB_PASSWORD);
// Tell the db that we use utf-8
$conn->query("SET NAMES utf8");

// Create the jqGrid instance
$grid = new jqGridRender($conn);
// Write the SQL Query
$grid->SelectCommand 'SELECT EmployeeID, FirstName, LastName, HomePhone, City FROM employees';
// Set the table to where you update the data
$grid->table 'employees';
// Set output format to json
$grid->dataType 'json';
// Let the grid create the model
$grid->setColModel();
// Set the url from where we obtain the data
$grid->setUrl('grid.php');
// Set some grid options
$grid->setGridOptions(array(
    
"rowNum"=>10,
    
"rowList"=>array(10,20,30),
    
"sortname"=>"EmployeeID"
));
$grid->setColProperty('EmployeeID', array("label"=>"ID""width"=>50));

$selectorder = <<<ORDER
function(rowid, selected)
{
    if(rowid != null) {
        jQuery("#detail").jqGrid('setGridParam',{postData:{EmployeeID:rowid}});
        jQuery("#detail").jqGrid('setColProp','EmployeeID',{editoptions:{defaultValue:rowid}});
        jQuery("#detail").trigger("reloadGrid");
        // Enable CRUD buttons in navigator when a row is selected
        jQuery("#add_detail").removeClass("ui-state-disabled");
        jQuery("#edit_detail").removeClass("ui-state-disabled");
        jQuery("#del_detail").removeClass("ui-state-disabled");
    }
}
ORDER;
// We should clear the grid data on second grid on sorting, paging, etc.
$cleargrid = <<<CLEAR
function(rowid, selected)
{
   // clear the grid data and footer data
    jQuery("#detail").jqGrid('clearGridData',true);
    // Disable CRUD buttons in navigator when a row is not selected
    jQuery("#add_detail").addClass("ui-state-disabled");
    jQuery("#edit_detail").addClass("ui-state-disabled");
    jQuery("#del_detail").addClass("ui-state-disabled");
}
CLEAR;

$grid->setGridEvent('onSelectRow'$selectorder);
$grid->setGridEvent('onSortCol'$cleargrid);
$grid->setGridEvent('onPaging'$cleargrid);
// Enable navigator
$grid->navigator true;
// Enable only editing
$grid->setNavOptions('navigator', array("excel"=>false,"add"=>false,"edit"=>false,"del"=>false,"view"=>false));
// Enjoy
$grid->renderGrid('#grid','#pager',truenullnulltrue,true);

detail.php.
<?php
require_once '../../jq-config.php';
// include the jqGrid Class
require_once ABSPATH."php/PHPSuito/jqGrid.php";
// include the driver class
require_once ABSPATH."php/PHPSuito/DBdrivers/jqGridPdo.php";
// Connection to the server
$conn = new PDO(DB_DSN,DB_USER,DB_PASSWORD);
// Tell the db that we use utf-8
$conn->query("SET NAMES utf8");
// Get the needed parameters passed from the main grid
$rowid jqGridUtils::GetParam('EmployeeID'0);
// Create the jqGrid instance
$grid = new jqGridRender($conn);
// Write the SQL Query
$grid->SelectCommand "SELECT OrderID, RequiredDate, ShipName, ShipCity, Freight, EmployeeID FROM orders WHERE EmployeeID= ?";
// set the ouput format to json
$grid->dataType 'json';
// Let the grid create the model
$grid->setPrimaryKeyId('OrderID');
$grid->table "orders";
$grid->setColModel(null, array((int)$rowid));
// Set the url from where we obtain the data
$grid->setUrl('detail.php');
// Set some grid options
$grid->setGridOptions(array(
    
"rowNum"=>10,
    
"footerrow"=>true,
    
"userDataOnFooter"=>true,
    
"sortname"=>"OrderID",
    
"height"=>110
    
));
// Change some property of the field(s)
$grid->setColProperty("RequiredDate", array(
    
"formatter"=>"date",
    
"formatoptions"=>array("srcformat"=>"Y-m-d H:i:s","newformat"=>"m/d/Y"),
    
"search"=>false
    
)
);
// on beforeshow form when add we get the customer id and set it for posting
$beforeshow = <<<BEFORE
function(formid)
{
var srow = jQuery("#grid").jqGrid('getGridParam','selrow');
if(srow) {
    var gridrow = jQuery("#grid").jqGrid('getRowData',srow);
    $("#EmployeeID",formid).val(gridrow.EmployeeID);
}
}
BEFORE;

// disable the CRUD buttons when we initialy load the grid
$initgrid = <<< INIT
jQuery("#add_detail").addClass("ui-state-disabled");
jQuery("#edit_detail").addClass("ui-state-disabled");
jQuery("#del_detail").addClass("ui-state-disabled");
INIT;

$grid->setUserTime("m/d/Y");
//$grid->debug = true;
$grid->showError true;
$grid->setJSCode($initgrid);
$grid->setColProperty("EmployeeID",array("hidden"=>false,"width"=>20,"editoptions"=>array("readonly"=>true)));
$grid->setColProperty("OrderID",array("editable"=>false));
$grid->navigator true;
$grid->setNavOptions('navigator', array("excel"=>true,"add"=>true,"edit"=>true,"del"=>true,"view"=>false));
$grid->setNavEvent('add''beforeShowForm'$beforeshow);
$grid->setNavOptions('add', array("recreateForm"=>true));
$grid->setNavOptions('edit', array("recreateForm"=>true));
// Enjoy
$summaryrow = array("Freight"=>array("Freight"=>"SUM"));
$grid->renderGrid("#detail","#pgdetail"true$summaryrow, array((int)$rowid), true,true);