Get KoolPHP UI with 30% OFF!

Persistent data?

Martin
I use the MySQLPivotDataSource as the data source to populate the Pivot. The DS loads the data from the database every time I reorder fields, or when I ellapse/collapse them. There is a noticeable delay when Pivot loads a large amount of data. I switched on Ajax and the Caching property but it did not really help. Data is read out of the database all the time. Here is the code I used:
$ds = new MySQLPivotDataSource($db_conn);
$ds->select("customerNumber, paymentDate, amount")->from("payments");
//....
$pivot = new KoolPivotTable("pivot");
$pivot->DataSource = $ds;
$pivot->AjaxEnabled = true;
$pivot->AllowCaching = true;

How can I avoid loading the data from the database over and over? I'd like to load the data only first time if it is not the Ajax callback. Is it possible? For example, the DataGrid has the "ArrayDataSource" data source. I could use it to refresh the grid data from the session variable by Ajax postback. But I did not find similar data source for Pivot. What is the right way to do it?
Thank you.
Posted Oct 2, 2015 Kool
Martin
I found this solution:
Make a new class that inherits from MySQLPivotDataSource, override the _queryall() method and define the new method Reset(). In this example, I'm using $_SESSION variable for persistency.
class PersistentPivotDataSource extends MySQLPivotDataSource
{
	function Reset()
	{
		global $_SESSION;
		$_SESSION["pivot_data"] = null;
		unset($_SESSION["pivot_data"]);
	}
	
	function _queryall($query)
	{
		if (isset($_SESSION["pivot_data"][$query]))
			return unserialize($_SESSION["pivot_data"][$query]);
		
		$data = parent::_queryall($query);
		$_SESSION["pivot_data"][$query] = serialize($data);
		return $data;
	} 
}

Make PersistentPivotDataSource instance as the data source and call the Reset() method if it is not Ajax callback:
$ds = new PersistentPivotDataSource($db_conn);
if (!$koolajax->isCallback)
{
	$ds->Reset();
}
$ds->select("select ...");
$pivot = new KoolPivotTable("pivot");
...

The solution assumes that the underlying data do not get modified in the database during the session; which was my case. If the underlying data is modified in the database during the same session then you get inconsistent results.
Please, let me know if there is a better solution.
Thanks!
PS: The KooPHPSuite product is an excellent tool!
Posted Oct 2, 2015 Kool -
Peter
Your solution is awesome. You can improve by using caching system may be, MemCache or Apc Cache in the same manner. And we actually take this as suggestion to improve speed for KoolPivotTable.
Posted Oct 3, 2015 Kool