Check documentation for the latest version of dhtmlxSuite Saving Grid Configuration in Cookies DHTMLX Docs

Saving Grid Configuration in Cookies

Common

The library provides a number of methods to manipulate cookies. Methods can take the following parameters:

  1. name - (optional) the cookie name;
  2. param - (optional) additional parameters added to cookie.

The stated functionality requires PRO version of the dhtmlxGrid (or DHTMLX Suite) package.


Using cookies

mygrid = new dhtmlXGridObject('gridbox');
mygrid.enableAutoSaving("some_name","expires=Fri, 31-Dec-2010 23:59:59 GMT");


Table 1 The cookies API
Method Description
Automatic saving to cookie
enableAutoSaving(name,param) enables automatic saving of the columns order (an array of ids), size and sorting type
enableAutoHiddenColumnsSaving(name,param) enables automatic saving of the columns states (hidden/shown)
enableAutoSizeSaving(name,param) enables automatic saving of the columns sizes
enableOrderSaving(name,param) enables automatic saving of the columns order (an array of ids)
enableSortingSaving(name,param) enables automatic saving of the columns sorting types
Manual saving to cookie
saveHiddenColumnsToCookie(name,param) saves the columns states (hidden/shown)
saveOrderToCookie(name, param) saves the columns order (an array of ids)
saveSortingToCookie(name,param) saves the columns sorting types
saveSizeToCookie(name,param) saves the columns sizes
Loading from cookies
loadHiddenColumnsFromCookie(name) loads the columns states (hidden/shown) from cookie
loadOrderFromCookie(name) loads the columns order (an array of ids) from cookie
loadSizeFromCookie(name) loads the columns sizes from cookie
loadSortingFromCookie(name) loads the columns sorting types from cookie
Clearing cookies
clearConfigCookie(name) clears the specified cookie

Some tips on automatic saving

While using automatic saving remember the following rules:

  1. the 'enable' and 'load' methods are called after grid initialization but before data loading;
  2. if you need to restore several cookie data you should follow the specific calling order. The correct order is shown in the code snippet below;
  3. the 'enable' methods must be called only AFTER calling the 'load' methods.

Automatic saving to cookie. The order of calling the related methods

mygrid = new dhtmlXGridObject('gridbox');
...
mygrid.init(); // firstly, initialize the grid
 
 
mygrid.loadOrderFromCookie();  // then restore the required data
mygrid.loadSizeFromCookie();
mygrid.loadSortingFromCookie();
mygrid.loadHiddenColumnsFromCookie();
 
 
mygrid.enableAutoSizeSaving(); // enable saving cookies 
mygrid.enableSortingSaving();
mygrid.enableOrderSaving();
mygrid.enableAutoHiddenColumnsSaving();
 
mygrid.load("data.php");   // load data to the grid

Related sample:  Saving/restoring columns' states

Back to top