TreeGrid v6.0

Configuration in cookies

TreeGrid documentation index

 

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

Attributes <C Visible>, <C Width> and positions of tags <C> inside their section

 

<Cfg Sort AutoSort Sorted/>

<Cfg Group Grouped/>

<Cfg SearchExpression SearchAction SearchMethod SearchCaseSensitive SearchCells SearchDefs SearchCols Searched/>

<Filter> cell values and cell Filter attribute and <Cfg Filtered/> attribute.

 

<Cfg ShowDeleted Calculated AutoUpdate ShowDrag AllPages Hover SortIcons />

 

 

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.

 

<Cfg>                int          Version                                                                                                                                         chg 6.4 .

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)

 

<Cfg>                bool       AutoVersion    [1]                                                                                                                   new 6.4 .

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.

 

<Cfg>                int          PersistentCfg              [0]                                                                                                      upd 7.0 .

If set to 1 or 2 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.

 

<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 or grid/Cfg attribute.

For example “R1,Col1,R6,Col7CanEdit,,Adding” = saves values R1.Col1 and R6.Col7CanEdit and Cfg.Adding

! 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”));

 

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=/”.

 

API event          bool       OnLoadCfg                    (TGrid grid)                                                                                                    .

Called when configuration is being loaded, return true to suppress loading. Called even if SuppressCfg set.

 

API event          void       OnCfgLoaded             (TGrid grid)                                                                                                    .

Called after configuration is loaded to provide own update to cfg.

 

API event          bool       OnSaveCfg                     (TGrid grid)                                                                                                    .

Called when configuration is being saved to cookies, return true to suppress saving. Called even if SuppressCfg set.

 

API method      void       LoadCfg ( )                                                                                                                                               .

Loads configuration from cookies. Does not display any changes.

 

API method      void       SaveCfg   ( )                                                                                                                                               .

Saves configuration to cookies.

Call it after some custom setting changed to save changes to cookies.

 

global func.      void       SaveCache  (string id, string val)                                                                                            upd 7.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>

 

global func.      string    LoadCache        (string id)                                                                                                       upd 7.0 .

Loads and returns value from persistent cache saved by SaveCache function.