Clear cookies for a grid

We have more than 1 grid on a HTML page. What I want to do is if user generates the HTML and changes the source of one of the grid, then clear only that grid’s cookies.

I have following order in my implementation:


Automatic saving to cookie. The order of calling the related methods
mygrid1 = new dhtmlXGridObject(‘gridbox’);

mygrid1.init(); // firstly, initialize the grid
mygrid1.enableHeaderMenu();

mygrid1.loadSizeFromCookie(“cookie1Name”);
mygrid1.loadHiddenColumnsFromCookie(“cookie1Name”);

mygrid1.enableAutoSizeSaving(“cookie1Name”, EXPIRATIONDATE); // enable saving cookies
mygrid1.enableAutoHiddenColumnsSaving(“cookie1Name”, EXPIRATIONDATE);

mygrid1.load(“mygrid1.json”, “json”); // load data to the grid


Automatic saving to cookie. The order of calling the related methods
mygrid2 = new dhtmlXGridObject(‘gridbox’);

mygrid2.init(); // firstly, initialize the grid
mygrid2.enableHeaderMenu();

mygrid2.loadSizeFromCookie(“cookie1Name”);
mygrid2.loadHiddenColumnsFromCookie(“cookie1Name”);

mygrid1.enableAutoSizeSaving(“cookie2Name”, EXPIRATIONDATE); // enable saving cookies
mygrid1.enableAutoHiddenColumnsSaving(“cookie2Name”, EXPIRATIONDATE);

mygrid2.load(“mygrid2.json”, “json”); // load data to the grid


Please Advise.

Hello,
We have used mygrid.clearConfigCookie(‘cookie1Name’); to remove a cookie for individual grids.

If we use “myGrid.clearConfigCookie();” without the cookie name. Would it clear all the saved configurations for that specific grid.

My question is why parameter is made optional? What would happen if we do not send cookie name?

Note: I am trying to load and reset hidden columns and their sizes.

If we use “myGrid.clearConfigCookie();” without the cookie name. Would it clear all the saved configurations for that specific grid.
That’s right. If you need to clear some specific cookie parameter you may define the name of the cookie.

Actually it is not clearing grid configurations for us. I have following code in my HTML file:
if(document.cookie.indexOf(“UNIQUE_GRID_GUID_TABLENAME”) < 0)
{
myGrid.clearConfigCookie();// Clear the previous configuration of the grid if table name has changed.
}

We have written the above logic after we create dhtmlxGridObject. According to my understanding, this loc should clear previous stored configuration if source table name is changed for myGrid. Is there something missing?

Please Advise.

clearConfigCookie() method works well for me locally.
It clears all the saved grid configuration.
If the problem still occurs for you please, share with a demo link or provide with a complete demo, where the problem can be reconstructed.

Can i please send the complete demo to support@dhtmlx.com and not upload it here?

You may try to send it to the support@dhtmlx.com with the note referring to the current topic or you can open a ticket at support.dhtmlx.com

We don’t have active support account now. So, I will mention you name and ticket number in subject line.

Thanks in advance. :slight_smile:

Below is the text from Document.Cookie which shows that grid configuration was not cleared when HTML file was generated.
Cookie name’s syntax is: {GRID_GUID}_TABLE_NAME_NumeOfColumns

gridSettings{6B5B429E-9814-481B-A7DB-AC5378999CE9}_FIRST_TABLE_NAME1_34
||||1----1-1-1–1-1-1-1-1----------1-1-1-1-1–1—1–1
local/F:/SOMEPATH/REPORTS/
1088
798222720
102790430
3617931295
30523838
*
gridSettings{6B5B429E-9814-481B-A7DB-AC5378999CE9}_TABLE_NAME_5
||||–1-1-1
local/F:/SOMEPATH/REPORTS/
1088
798222720
102790430
2649754183
30523839
*
gridSettings{6B5B429E-9814-481B-A7DB-AC5378999CE9}_TABLE_NAME_4
||||-1-1
local/F:/SOMEPATH/REPORTS/
1088
798222720
102790430
3757116951
30523839
*
gridSettings{6B5B429E-9814-481B-A7DB-AC5378999CE9}_TABLE_NAME_2
3-4—|39-61-51-47-53|||
local/F:/SOMEPATH/REPORTS/
1088
798222720
102790430
739721225
30523840
*
gridSettings{6B5B429E-9814-481B-A7DB-AC5378999CE9}_TABLE_NAME_1
5----|100-136-120-132-158|||
local/F:/SOMEPATH/REPORTS/
1088
798222720
102790430
2337017429
30523840
*

I have send you a demo of this functionality not working on the support email address. Also, I wanted to ask if there is a way to change the expiration date of the cookies already created for a grid?

Your demo was blocked by firewall. Could you please, reattach it or upload to a third-side resource.

About the expiration changing: you may set the expiration in a second attribute of the cookie saving parameter. For example:
myGrid.saveHiddenColumnsToCookie(“some_name”,“expires=Fri, 31-Dec-2010 23:59:59 GMT”);

One suggestion in the actual given code, no need to init if load is used.
Ensure to load from cookies before saving to cookies. Below code worked for us.

myGrid.loadHiddenColumnsFromCookie("ckGrid"); myGrid.loadSizeFromCookie("ckGrid"); myGrid.saveHiddenColumnsToCookie("ckGrid"); myGrid.enableAutoSizeSaving("ckGrid");
For Cleaning :

myGrid.clearConfigCookie("ckGrid");