KoolGrid supports auto-generating columns from your database. This feature is extremely useful in saving your time.
- - $AutoGenerateColumns : Create columns base on the sql query
- - $AutoGenerateRowSelectColumn : Create Row Select Column
- - $AutoGenerateDeleteColumn : Create Delete button column
- - $AutoGenerateEditColumn : Create Edit button column
- - $AutoGenerateExpandColumn : Create DetailTable Expand Column
<?php
require $KoolControlsFolder."/KoolAjax/koolajax.php";
$koolajax->scriptFolder = $KoolControlsFolder."/KoolAjax";
require $KoolControlsFolder."/KoolGrid/koolgrid.php";
require $KoolControlsFolder."/KoolGrid/ext/datasources/MySQLiDataSource.php";
$ds = new MySQLiDataSource($db_con);//This $db_con link has been created inside KoolPHPSuite/Resources/runexample.php
$ds->SelectCommand = "select customerNumber as pk, customerNumber,customerName,phone,city from customers";
$ds->UpdateCommand = "update customers set customerNumber=@customerNumber, customerName='@customerName', phone='@phone', city='@city' where customerNumber=@pk";
$ds->DeleteCommand = "delete from customers where customerNumber=@pk";
$ds->InsertCommand = "insert into customers (customerNumber,customerName,phone,city) values (@customerNumber,'@customerName','@phone','@city');";
$grid = new KoolGrid("grid");
$grid->scriptFolder = $KoolControlsFolder."/KoolGrid";
$grid->styleFolder="default";
$grid->DataSource = $ds;
$grid->Width = "655px";
$grid->AllowEditing = true;
$grid->AllowDeleting = true;
$grid->AjaxEnabled = true;
$grid->AutoGenerateRowSelectColumn = true;
$grid->AutoGenerateColumns = true;
$grid->DisableAutoGenerateDataFields = "pk";
$grid->AutoGenerateDeleteColumn = true;
$grid->AutoGenerateEditColumn = true;
$grid->MasterTable->Pager = new GridPrevNextAndNumericPager();
$grid->Process();
?>
<form id="form1" method="post">
<?php echo $koolajax->Render();?>
<?php echo $grid->Render();?>
</form>