Skip to content

Instantly share code, notes, and snippets.

@gridphp
Created March 27, 2023 15:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gridphp/c85ee8db525ae46de40b118718fca241 to your computer and use it in GitHub Desktop.
Save gridphp/c85ee8db525ae46de40b118718fca241 to your computer and use it in GitHub Desktop.
Load different detail grid structure using ajax
<?php
/**
* PHP Grid Component
*
* @author Abu Ghufran <gridphp@gmail.com> - http://www.phpgrid.org
* @version 2.0.0
* @license: see license.txt included in package
*/
// include db config
include_once("../../config.php");
// include and create object
include(PHPGRID_LIBPATH."inc/jqgrid_dist.php");
// master grid
// Database config file to be passed in phpgrid constructor
$db_conf = array(
"type" => PHPGRID_DBTYPE,
"server" => PHPGRID_DBHOST,
"user" => PHPGRID_DBUSER,
"password" => PHPGRID_DBPASS,
"database" => "information_schema"
);
$grid = new jqgrid($db_conf);
$opt["caption"] = "Clients Data";
$opt["height"] = "150";
$opt["multiselect"] = true;
// keep multiselect only by checkbox, otherwise single selection
$opt["multiboxonly"] = true;
// disable detail grid import if client_id 5 is selected
$opt["onSelectRow"] = "function(rid){
var rowdata = $('#list1').getRowData(rid);
$('#detail_div').load('?grid_id=list2&oper=ajaxload&dbname='+rowdata['TABLE_SCHEMA']+'&tname='+rowdata['TABLE_NAME']);
}";
$grid->set_options($opt);
$grid->select_command = "select concat(table_schema,table_name) as id, table_schema,table_name,table_rows from tables where table_type = 'BASE TABLE'";
$grid->table = "information_schema";
$out_master = $grid->render("list1");
// detail grid
if (!empty($_GET["tname"]))
{
$db_conf["database"] = $_GET["dbname"];
$grid = new jqgrid($db_conf);
$tname = $_GET["tname"];
$opt = array();
$opt["height"] = ""; // autofit height of subgrid
$opt["caption"] = "Invoice Data"; // caption of grid
$opt["multiselect"] = true; // allow you to multi-select through checkboxes
$grid->set_options($opt);
$grid->table = $tname;
// generate grid output, with unique grid name as 'list1'
$out_detail = $grid->render("list2");
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html>
<head>
<link rel="stylesheet" type="text/css" media="screen" href="../../lib/js/themes/redmond/jquery-ui.custom.css"></link>
<link rel="stylesheet" type="text/css" media="screen" href="../../lib/js/jqgrid/css/ui.jqgrid.css"></link>
<script src="../../lib/js/jquery.min.js" type="text/javascript"></script>
<script src="../../lib/js/jqgrid/js/i18n/grid.locale-en.js" type="text/javascript"></script>
<script src="../../lib/js/jqgrid/js/jquery.jqGrid.min.js" type="text/javascript"></script>
<script src="../../lib/js/themes/jquery-ui.custom.min.js" type="text/javascript"></script>
</head>
<body>
<div style="margin:10px">
<div>
<?php echo $out_master ?>
</div>
<br>
<div id="detail_div">
<?php echo $out_detail; ?>
</div>
</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment