Get KoolPHP UI with 30% OFF!

Using the Advanced Array Datasource and refreshing your table on insert

Anthony Amolochitis
If you've used the advanced array datasource, you've noticed it is super fast, but always a pain to deal with unless you've discovered what you need to do to refresh your data.
It's actually quite simple. You need to reload the data array after your Insert/Edit/Delete operations. How do you do it.
1. Create your koolgrid as usual.
2. Add an event handler.
3. On insert, make use of a global, or object property that you can access in your grid's event handler functions
- OnTableViewPreRender
- OnBeforeConfirmInsert
On your insert function, OnBeforeConfirmInsert, if it completes the process successfully, then set this variable to true.
Example :
... 
  // This variable will be checked in my tableview prerender function
  $_REQUEST['SavingNewWebLeadFieldData'] = true ;
...

Now, in your OnTableViewPreRender do the following :
    /**
     * Occurring before the grid renders. You can make any neccessary changes here before the grid is in rendering process.
     * 1.  Check and see if the array datasource needs to refresh.
     *     Variable : $_REQUEST['SavingNewWebLeadFieldData'] is boolean
     *     It tells the grid prerender process refresh the data array
     * @param GridTableView  $grid
     * @param array $args
     */
    function OnTableViewPreRender($grid,$args)
    {
        
        if( isset( $_REQUEST['SavingNewWebLeadFieldData'] ) && is_bool( $_REQUEST['SavingNewWebLeadFieldData'] ) )
        {
            if( $_REQUEST['SavingNewWebLeadFieldData'] === true )
            {
                $this->grid->BuildDataSourceArray(); // original grid object set on the constructor.
                $grid->DataSource = new AdvancedArrayDataSource( $this->grid->GridMappedFields );
                $grid->refresh();
            }
            
        }
    }

Hope this helps somebody.
Posted Feb 16, 2016 Kool