Get KoolPHP UI with 30% OFF!

Adding a class construct method to access the koolgrid object at anytime

Anthony Amolochitis
<?php
        // create the class 
        class MyGridEventHandler extends GridEventHandler
	{
             /** @var KoolGrid */
             var $KoolGrid ;
            function __construct( &$grid )
            {
                $this->KoolGrid = $grid ;
            }
          /** You may have other methods here as needed **/
                
	}
	
	//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( $grid ); // pass in the grid to the event handler.  Now you have access to the grid object directly throughout the event handler at all times	
	
	//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>
Posted Dec 5, 2015 Kool -
Peter
It's great :)
Posted Dec 5, 2015 Kool