You can use row selection in many scenarios. In this sample we are hooking the onSelectRow client-side event of the grid.
You can use the event handler to write custom code and databind a second grid with details. Here, clicking on a Customer will show a details grid with all Orders for that customer (data from Northwind database).
Please, take a look at the code.
<?php
require_once '../../../../php/demo/tabs.php';
ini_set('display_errors',1);
?>
<!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>Master</b>
<?php require_once ("grid.php");?>
</div>
<div>
<b>Detail</b>
<?php require_once '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/jqGridArray.php";
// Connection to the server
$arhivaPT = array();
for ($i = 0; $i < 10; $i++)
{
$arhivaPT[$i]['CodPT'] = (integer)$i+1;
$arhivaPT[$i]['CodParam'] = 'CP_'.($i+1);
$arhivaPT[$i]['Denumire'] = 'Denumire_'.($i+1);
$arhivaPT[$i]['Parametri'] = 'Parametri_'.($i+1);
}
$gridPT = new jqGridArray();
$grid = new jqGridRender($gridPT);
$grid->SelectCommand = "SELECT * FROM arhivaPT";
$grid->dataType = 'json';
$grid->setPrimaryKeyId('CodParam');
$grid->setColModel();
$grid->setUrl('grid.php');
$grid->setGridOptions(array(
"width"=>500,
"rowNum"=>10,
"rowList"=>array(10,20,30),
"sortname"=>"Denumire"
));
$grid->setColProperty("CodPT", array("hidden"=>true));
$grid->setColProperty("CodParam", array("hidden"=>true));
$grid->setColProperty("Denumire", array("label"=>"Denumire", "width"=>250,"align"=>"left","hidden"=>false));
$grid->setColProperty("Parametri", array("label"=>"Parametri", "width"=>250,"align"=>"left","hidden"=>false));
$onselect = <<< ONSELECT
function(rowid, selected){
if(rowid != null) {
rowdata = jQuery(this).jqGrid('getRowData', rowid);
jQuery("#detail").jqGrid('setGridParam',{postData:{COL1: rowdata.CodPT, COL2 : rowdata.CodParam}});
jQuery("#detail").trigger("reloadGrid");
}
}
ONSELECT;
$grid->setGridEvent('onSelectRow', $onselect);
$grid->navigator = true;
$grid->toolbarfilter = true;
$grid->setFilterOptions(array("searchOnEnter"=>false));
$grid->setNavOptions('navigator', array("excel"=>false,"add"=>false,"edit"=>false,"del"=>false,"view"=>false,"csv"=>false, "pdf"=>false));
$grid->setNavOptions('search',array("multipleSearch"=>false));
$grid->renderGrid('#grid','#pager',true, null, null, true,true);
detail.php.
<?php
require_once '../../jq-config.php';
// include the jqGrid Class
if(!class_exists('jqGrid')) {
include_once ABSPATH."php/PHPSuito/jqGrid.php";
}
// include the driver class
include_once ABSPATH."php/PHPSuito/DBdrivers/jqGridArray.php";
// Connection to the server
$CodPT = jqGridUtils::GetParam("COL1");
$CodParam = jqGridUtils::GetParam("COL2");
$arhivaDate = array();
$arhivaDate[] = array("Ziua"=>"10.09.2015_14:00:00","readouttime"=>"2015-09-10 14:00:00.000","Pres_ACM"=>"2.826","Pres_INC"=>"0","Temp_ACM_P4"=>"64","Temp_EXT"=>"18.56","Temp_INC"=>"30.62","Temp_Tur_TF"=>"66.93");
$arhivaDate[] = array("Ziua"=>"10.09.2015_13:00:00","readouttime"=>"2015-09-10 14:00:00.000","Pres_ACM"=>"2.826","Pres_INC"=>"0","Temp_ACM_P4"=>"64","Temp_EXT"=>"18.56","Temp_INC"=>"30.62","Temp_Tur_TF"=>"66.93");
$arhivaDate[] = array("Ziua"=>"10.09.2015_12:00:00","readouttime"=>"2015-09-10 14:00:00.000","Pres_ACM"=>"2.826","Pres_INC"=>"0","Temp_ACM_P4"=>"64","Temp_EXT"=>"18.56","Temp_INC"=>"30.62","Temp_Tur_TF"=>"66.93");
$arhivaDate[] = array("Ziua"=>"10.09.2015_11:00:00","readouttime"=>"2015-09-10 14:00:00.000","Pres_ACM"=>"2.826","Pres_INC"=>"0","Temp_ACM_P4"=>"64","Temp_EXT"=>"18.56","Temp_INC"=>"30.62","Temp_Tur_TF"=>"66.93");
$arhivaDate[] = array("Ziua"=>"10.09.2015_10:00:00","readouttime"=>"2015-09-10 14:00:00.000","Pres_ACM"=>"2.826","Pres_INC"=>"0","Temp_ACM_P4"=>"64","Temp_EXT"=>"18.56","Temp_INC"=>"30.62","Temp_Tur_TF"=>"66.93");
$arhivaDate[] = array("Ziua"=>"10.09.2015_09:00:00","readouttime"=>"2015-09-10 14:00:00.000","Pres_ACM"=>"2.826","Pres_INC"=>"0","Temp_ACM_P4"=>"64","Temp_EXT"=>"18.56","Temp_INC"=>"30.62","Temp_Tur_TF"=>"66.93");
$arhivaDate[] = array("Ziua"=>"10.09.2015_08:00:00","readouttime"=>"2015-09-10 14:00:00.000","Pres_ACM"=>"2.826","Pres_INC"=>"0","Temp_ACM_P4"=>"64","Temp_EXT"=>"18.56","Temp_INC"=>"30.62","Temp_Tur_TF"=>"66.93");
//var_dump($arhivaDate);
$connGrd = new jqGridArray();
$grid = new jqGridRender($connGrd);
$grid->SelectCommand = "SELECT * FROM arhivaDate";
$grid->dataType = 'json';
$grid->setPrimaryKeyId('Ziua');
$grid->setColModel();
$grid->setUrl('detail.php');
//$grid->debug = true;
$grid->showError = true;
$grid->setGridOptions(array(
"width"=>700,
"rowNum"=>10,
"rowList"=>array(10,20,30)
));
$grid->navigator = true;
$grid->setNavOptions('navigator', array("excel"=>false,"add"=>false,"edit"=>false,"del"=>false,"view"=>false,"csv"=>false, "pdf"=>false));
$grid->setNavOptions('search',array("multipleSearch"=>false));
$grid->renderGrid("#detail","#pgdetail",true, null, null, true,true);