KoolGrid support unlimited levels of table details.
In above example, A three level hierarchy is demonstrated with Customer Master Table and two nested Detail Tables Orders and OrderDetails.
<?php
require $KoolControlsFolder."/KoolAjax/koolajax.php";
$koolajax->scriptFolder = $KoolControlsFolder."/KoolAjax";
require $KoolControlsFolder."/KoolGrid/koolgrid.php";
require $KoolControlsFolder."/KoolGrid/ext/datasources/MySQLiDataSource.php";
$ds_customer = new MySQLiDataSource($db_con);//This $db_con link has been created inside KoolPHPSuite/Resources/runexample.php
$ds_customer->SelectCommand = "select customerNumber,customerName,phone,city from customers";
$ds_order = new MySQLiDataSource($db_con);//This $db_con link has been created inside KoolPHPSuite/Resources/runexample.php
$ds_order->SelectCommand = "select orderNumber,orderDate,status,customerNumber from orders";
$ds_order_detail = new MySQLiDataSource($db_con);//This $db_con link has been created inside KoolPHPSuite/Resources/runexample.php
$ds_order_detail->SelectCommand = "select orderNumber,productName,quantityOrdered,priceEach from orderdetails,products where orderdetails.productCode=products.productCode";
$grid = new KoolGrid("grid");
$grid->scriptFolder = $KoolControlsFolder."/KoolGrid";
$grid->styleFolder="default";
$grid->Width = "655px";
$grid->RowAlternative = true;
$grid->AjaxEnabled = true;
$grid->AjaxLoadingImage = $KoolControlsFolder."/KoolAjax/loading/5.gif";
$table_order_detail = new GridTableView();
$table_order_detail->Width = "100%";
$table_order_detail->DataSource = $ds_order_detail;
$table_order_detail->AddRelationField("orderNumber","orderNumber");
$table_order_detail->AutoGenerateColumns = true;//Auto Generate all column from tables
$table_order_detail->DisableAutoGenerateDataFields = "orderNumber";//Disable generate column for orderNumber data fields.
$table_order = new GridTableView();
$table_order->Width = "100%";
$table_order->DataSource = $ds_order;
$table_order->AddRelationField("customerNumber","customerNumber");
$table_order->AutoGenerateExpandColumn = true;
$table_order->AutoGenerateColumns = true;
$table_order->DisableAutoGenerateDataFields = "customerNumber";
$table_order->AddDetailTable($table_order_detail);
$grid->MasterTable->DataSource = $ds_customer;
$grid->MasterTable->AutoGenerateExpandColumn = true;
$grid->MasterTable->AutoGenerateColumns = true;
$grid->MasterTable->AddDetailTable($table_order);
$grid->MasterTable->Pager = new GridPrevNextAndNumericPager();
$grid->Process();
?>
<form id="form1" method="post">
<?php echo $koolajax->Render();?>
<?php echo $grid->Render();?>
</form>