Assuming you have the same table mydata that comes with the koolphp install.
<?php
// create the class
class MyGridEventHandler extends GridEventHandler
{
///////////////// INSERT METHODS /////////////////
function OnBeforeConfirmInsert($tableview,$args)
{
//$tableview: The grid tableview object.
//$args["NewDataItem"]: New dataitem
return true;//Approve the action. If false, then the form will stay open. Great for validation routines
}
function OnConfirmInsert($tableview,$args)
{
// $tableview: The grid tableview object.
// $args["NewDataItem"]: New dataitem posted back
// $args["Successful"]: Bool value which indicates whether the insert is successful.
}
///////////////// EDIT METHODS /////////////////
function OnBeforeRowConfirmEdit($row,$args)
{
// $row: The grid row object.
// $row->GetTableView() Can return the table view for validation routines if needed. Great for small tables and checking for data already existing.
// View : http://doc.koolphp.net/Controls/KoolGrid/PHP/GridRow/index.php
// View : http://doc.koolphp.net/Controls/KoolGrid/PHP/GridTableView/index.php
// $args["NewDataItem"]: New dataitem.
return true;//Approve the action. If false, then the form will stay open. Great for validation routines
}
function OnRowConfirmEdit($row,$args)
{
//$row: The grid row object.
//$args["NewDataItem"]: New dataitem
//$args["Successful"]: Bool value which indicates whether the edit is successful.
}
///////////////// DELETE METHODS /////////////////
function OnBeforeRowDelete($row,$args)
{
//$row: The grid row object.
//$args: No data
return true;//Approve the action.
}
function OnRowDelete($row,$args)
{
//$row: The grid row object.
//$args["Successful"]: bool value indicating whether row is deleted sucessfully.
}
}
//Step 1: Register KoolGrid component to your page
require "KoolControls/KoolGrid/koolgrid.php";
require "KoolControls/KoolAjax/koolajax.php";
$koolajax->scriptFolder = "KoolControls/KoolAjax";
//Step 2: Create datasource
$db_con = mysql_connect('localhost','root','root');
mysql_select_db('mydata',$db_con);
$ds = new MySQLDataSource($db_con);
$ds->SelectCommand = "select customerNumber,customerName,phone,city from customers";
//Step 3: Init KoolGrid and settings
$grid = new KoolGrid("grid");
$grid->scriptFolder = "KoolControls/KoolGrid";
$grid->styleFolder="default";
$grid->DataSource = $ds;
$grid->AjaxEnabled = true;
$grid->Width = "655px";
$grid->AllowInserting = true;
$grid->AllowSorting = true;
$grid->AutoGenerateColumns = true;
$grid->MasterTable->Pager = new GridPrevNextAndNumericPager();
// add the event handler
$grid->EventHandler = new MyGridEventHandler();
//Step 4: Process Grid
$grid->Process();
?>
<html>
<head>
<title></title>
<?php echo $koolajax->Render();?>
</head>
<body>
<form id="form1" method="post">
<!-- Step 5: Get KoolGrid render -->
<?php echo $grid->Render();?>
</form>
</body>
</html>