Get KoolPHP UI with 30% OFF!

Grouping with form using POST method retrieves old grid data, GET method works ok.

Fred
The scenario is as simple as the grouping example, only with the addition of a form with POST method, when it's submitted it changes the query that populates the array that koolgrid uses with AdvancedArrayDataSource.
The form has a checkbox to show different results according if it's checked or not. So my dataset is different after a submit triggered by an event of that checkbox.
The data on the grid is ok and responding to what is expected but when grouping using any header it refreshes the grouped grid showing old data from a previous submit (the initial one from the fist time the page is loaded).
The grouped data is different from the data showed before grouping, but after ungrouping it remains with the "wrong/old" data.
The strange part is that changing the form method to GET that problem disappears, it works as expected grouping what is showed. So anywhere KoolAjax is keeping an old version of the data when using POST as the form submit method, but I couldn't figure it out where.
I've tried
$grid->KeepGridRefresh = true;
$grid->KeepViewStateInSession = false;

with no success.
Also changed the Datasource to SQLSRVDataSource with no difference in behaviour.
I don't want to use GET in order to not showing to final user filtering fields and session variales.
Chrome and Firefox same results.
Any ideas?
Tks!
Posted Aug 5 Kool
Anthony Amolochitis
Post your grid code.
I think I know what your problem is, but I would need to see what you're doing first.
Posted Aug 7 Kool
Fred
Hi, my grid code (simplified the rest) is :
	
if($idcustomer == 'on'){
$add = " idcustomer = 100 ";
}else{
$add = " name = 'john' ";
}
$sql = "Select idcustomer,name, surname,cdamostra from customer where $add ";
	$params = array();
	$options =  array( "Scrollable" => SQLSRV_CURSOR_STATIC );
	$ds = sqlsrv_query( $conn, $sql , $params, $options );
        $rows = array();
        while($r = sqlsrv_fetch_array( $ds, SQLSRV_FETCH_NUMERIC)) $rows[] = $r;
//koolgrid array preparation
       $rs = array();
       foreach($rows as $key=>$value) $rs[]=$value;
       $header = array('Id','Name','Surname','cdamostra');
       foreach ($rs as $k=>$a){
       $n=0;	
       foreach($a as $h){
       $rs[$k][$header[$n]]=$rs[$k][$n];
       unset($rs[$k][$n]);
	$n++;
       }
    }   
    //here I have an array named $rs for the grid.
        $KoolControlsFolder = "../KoolPHPSuite/KoolControls";//Relative path to "KoolPHPSuite/KoolControls" folder
	
	require $KoolControlsFolder."/KoolAjax/koolajax.php";
	$koolajax->scriptFolder = $KoolControlsFolder."/KoolAjax";
	require $KoolControlsFolder."/KoolGrid/koolgrid.php";
	require $KoolControlsFolder."/KoolGrid/ext/datasources/AdvancedArrayDataSource.php";
       $ds_order = new AdvancedArrayDataSource($rs);
	$grid = new KoolGrid("grid");
	$grid->scriptFolder = $KoolControlsFolder."/KoolGrid";
	$grid->Localization->Load($KoolControlsFolder."/KoolGrid/localization/pt.xml");
	$grid->styleFolder="office2010blue";
	$grid->Width = "100%";
	$grid->RowAlternative = true;
	$grid->AjaxEnabled = true;
	$grid->AjaxLoadingImage =  $KoolControlsFolder."/KoolAjax/loading/5.gif";
	$grid->AllowSorting = true;
	$grid->KeepGridRefresh = true;
	$grid->AllowScrolling = true;
	$grid->Height  = "700px";
	$grid->AllowResizing = true;
	$grid->AllowGrouping = true;
	$grid->MasterTable->ShowGroupPanel = true; 
	$grid->MasterTable->DataSource = $ds_order;
	$grid->MasterTable->Width = "100%";	
	$grid->MasterTable->AllowMultiSelecting = true;
	$grid->MasterTable->AutoGenerateColumns = true;
	$grid->KeepViewStateInSession = false;
	$grid->DisableAutoGenerateDataFields  = "cdamostra";
	$grid->Process();
<?php
echo $koolajax->Render();
?>
<form method"POST" name="pasar" action="<?=$_SERVER['PHP_SELF']?>">  //if I change POST to GET it works ok.
<input id="idcustomer" onChange="document.pasar.submit();" name="sitcoleta" type="checkbox"
</form>
<?php 
	echo $grid->Render();
?>
Posted Aug 7 , edited Aug 7 Kool
Anthony Amolochitis
Try adding a grid event handler. I had the same problem, but used the GridEventHandler to fix it by rebuilding the datasource before the grid was rendered.
 
class YourCustomGridEventHandler extends grideventhandler
{
    /**
     * Occurring before the grid renders. You can make any necessary changes here before the grid is in rendering process.
     * @param GridTableView  $grid
     * @param array $args
     */
    function OnTableViewPreRender( $grid , $args )
    {       
        $grid->DataSource = new AdvancedArrayDataSource( YourCustomerDataSource::Build( $Parameters_As_Needed_Here );
        $grid->refresh();
    }
}

// Where you create your grid object add something under it.
// you can add a constructor if you need to pass other values to it.
$grid = new KoolGrid("grid");
$grid->EventHandler    = new YourCustomGridEventHandler ();  // this lets you override the grid events
Posted Aug 7 , edited Aug 7 Kool