Configuration in cookies

TreeGrid documentation

Many TreeGrid settings are automatically saved in client browser and are persistent between sessions. So the server does not need to care about it.
The saved settings override the settings in xml, so the settings in xml are used only for the first visit, when no settings are saved in cookies.
When the grid layout is changed, you should increase Version attribute to delete old configuration from cookies and use the new setting from xml.
Since 6.4 the Version is automatically generated because of setting AutoVersion='1'.
You can suppress saving configuration completely by SuppressCfg='3' or you can suppress only some setting by appropriate ...Lap attribute (for example SortLap='1' suppresses only sorting).
Configuration is saved under the grid id name. Grids with the same id will share their saved settings, but only if cookie or persistent storage is shared between those pages.
You can control cookie setting also by API properties Grids.CookieExpires and Grids.CookieParam.

The settings are saved to cookies by default. Because of cookies size limit (4096 B) you can save it to browser persistent storage instead. The persistent storage is supported only by IE 5.0+ and Firefox 2.0+. See PersistentCfg attribute.

It is also possible to upload to and download from server the actual configuration in XML (Upload_Type="Settings") or in black box Cookie (Upload_Type="Cookie").

To cookies (or persistent storage) is saved by default

For grids with more columns to decrease cookie size of saved data, you should name columns as short as possible, the best to up to three characters.

To cookies (or persistent storage) you can also save:

Take care about the length of saved data, especially if you are saving to cookies and not to persistent storage. You can usually permit saving of these setting only for small grids.
<Cfg><treegrid/bdo> string

id

[...] Both letters lowercase!
Unique ID of created TreeGrid on the page. It must be string, not number, to not collide with grid indexes.
Under this name will be stored configuration to cookies or persistent storage if not set CfgId.
new 8.1 <Cfg> string

CfgId

Under this name will be stored configuration to cookies.
Useful to set when more grids on page share the same configuration.
chg 6.4 <Cfg> int

Version

Version of data. Grid loads configuration from cookies only if the Version is the same as saved.
Change this number whenever data structure (especially number of columns, column names and types) changes to delete old configuration saved to cookies.
Since 6.4 the not set Version is automatically generated when set AutoVersion='1' (it is set by default)
new 6.4 <Cfg> bool

AutoVersion

[1]
If set to 1, the configuration Version is automatically generated according to the actual values in XML layout.
Whenever is the XML layout changed (only the attributes saved to cookies), the whole cookie is cleared and new values from XML are used.
If set Version or Cookie attribute, the AutoVersion is ignored.
The XML attributes ignored in AutoVersion calculation: values (SaveValues), Selected (SaveSelected), Expanded (SaveExpanded), main tag width, scroll position.
Remember, when upgrading TreeGrid to higher version, there are often added new items to cookie, so in this case the Version changes and the old configuration is cleared when set AutoVersion='1'.
<Cfg> int

SuppressCfg

[0]
If does not use any client settings in cookies (0 - uses, 1 - does not load, 2 - does not save, 3 - nothing)
If set to 4 does not load or save configuration from cookies, but still accepts and returns configuration in Cookie attribute.
It is good to set SuppressCfg='1' for development.
new 8.0 <Cfg> int

DefaultCfg

[3]
Which default configuration is saved to be available to be restored by RestoreCfg
1 - default configuration in XML
2 - configuration loaded from cookies on start
3 - both
new 8.0 <Cfg> int

DefaultCfgMenu

[1]
Controls Defaults button in configuration menu.
0 - button will be hidden
1 - button loads default configuration in XML (must be set DefaultCfg to 1 or 3)
2 - button loads configuration loaded from cookies on start (must be set DefaultCfg to 2 or 3)
upd 11.0 <Cfg> int

PersistentCfg

[0]
If set, uses persistent browser cache instead of cookies for saving configuration.
The persistent cache can store much more data, at least one megabyte (shared among all pages).
(Since 7.0) This persistent cache is used as localStorage in IE8+, Firefox 3.0+, Chrome 4+, Safari 4+, Opera 10.5; Maximal capacity 5MB
IE6 and IE7 uses userData behavior with maximal capacity 128kB
Firefox 2.0 uses globalStorage with maximal capacity 1 MB
In many browsers the persistent cache is not used when running locally on protocol file://.
0 - use cookies, 1 - use persistent cache if available otherwise use cookies, 2 - use only persistent cache, if available, 3 - (new 11.0) use sessionStorage if available
chg 8.0 <Cfg> string[ ]

SaveAttrs

Comma separated array of pairs row_id, attribute_name. Saves all these attribute/cell values to cookies. To save cell value, just specify its column name (as even value).
If row_id (the odd item) is empty, saves attribute of <Cfg>.
You can also save any your custom row, column or grid/Cfg attribute.
For example "R1,Col1,R6,Col7CanEdit,Col1,CanEdit,,Adding" = saves values R1.Col1 and R6.Col7CanEdit, column Col1 attribute CanEdit and Cfg.Adding
Since 8.0 it can save also column attribute. In case the column name collides with row id, the column is used.
! Remember, the configuration from cookies is loaded after layout xml (if present) is loaded, so to save attributes from rows loaded in data xml is impossible !
<Cfg> int

SaveAttrsTrim

[50]
By default are all values saved by SaveAttrs trimmed to 50 characters, because the size of cookie is small, you can change the predefined length here.
<Cfg> string

Cookie

Whole configuration in string as it was saved to cookie. Use this attribute to get or return configuration saved on server by Upload_Type="Cookie". If this attribute is set, the configuration is loaded from it instead of cookies.
Loading configuration is still affected by SuppressCfg (see also its value 4), Version and other such settings.
Remember, this setting must not be modified, it must be completely the same as the setting returned by grid when saving.
To send configuration to server by API you can use such code: AjaxCall ("url to send", grid.GetXmlData("Cookie"));
or save it in API event: Grids.OnCfgSaved = function(G,cookie) { AjaxCall ("url to send", cookie, function(){}); }
global prop. int

Grids.CookieExpires

When configuration in cookies expires, 0 (default) never, 1 only this session, >1 after xxx seconds, or can be of type Date - exact expiration date.
global prop. string

Grids.CookieParam

Other cookie parameters (path, domain, secure) in string, starting with ';'. For example "; path=/".
upd 8.0 API event bool

OnLoadCfg

(TGrid grid, string cfg)
Called when configuration is being loaded, return true to suppress loading. Called even if SuppressCfg set.
(new 8.0) cfg is cookie string that was passed to LoadCfg, if any.
upd 8.0 API event void

OnCfgLoaded

(TGrid grid, string cfg)
Called after configuration is loaded to provide own update to cfg.
(new 8.0) cfg is cookie string that was passed to LoadCfg, if any.
upd 8.0 API event bool

OnSaveCfg

(TGrid grid, bool return)
Called when configuration is being saved to cookies, return true to suppress saving. Called even if SuppressCfg set.
(new 8.0) return is set to true if configuration is not saved to cookies, it is just read.
new 10.0 API event bool

OnCfgSaved

(TGrid grid, string cfg)
Called when TreeGrid cookie is to be saved to browser cookies or local storage, return true to suppress saving.
Here you can upload the cookie to server by AjaxCall to be later loaded to grid by Cookie attribute.
new 8.0 API event void

OnLoadCustomCfg

(TGrid grid, string custom, string cfg)
Called to load custom configuration saved by OnSaveCustomCfg.
The custom is the custom configuration string. Is null, if no custom configuration was saved.
cfg is cookie string that was passed to LoadCfg, if any.
new 8.0 API event string

OnSaveCustomCfg

(TGrid grid, bool return)
Called to add any custom string to saved configuration. Return the string to add.
return is set to true if configuration is not saved to cookies, it is just read.
upd 8.0 API method void

LoadCfg

(string cookie = null)
Loads configuration from cookies. Does not display any changes.
Since 8.0 it can be called also after grid is rendered to apply the configuration changes again.
Since 8.0 The cookie can be cookie string got by SaveCfg method or GetXmlData with Cookie setting.
upd 8.0 API method string

SaveCfg

(bool return = false)
Saves configuration to cookies.
Call it after some custom setting changed to save changes to cookies.
Since 8.0 If set return = true, it returns the configuration in string instead of saving it cookie. To be later used by LoadCfg or by Cookie attribute.
new 8.0 API method void

RestoreCfg

(int type = 1)
Reloads specified configuration saved by DefaultCfg
type = 1 - default configuration in XML, 2 - configuration loaded from cookies on start
upd 11.0 global func. void

SaveCache

(string id, string val, bool session = 0)
Saves value to persistent cache according to given id. See PersistentCfg.
You can also redefine this function to do your own caching mechanism when set <Cfg PersistentCfg>.
(Since 11.0) If set session = 1, it saves to sessionStorage instead of localStorage.
upd 11.0 global func. string

LoadCache

(string id, bool session = 0)
Loads and returns value from persistent cache saved by SaveCache function.
(Since 11.0) If set session = 1, it loads from sessionStorage instead of localStorage.