Start Building Professional
Web Apps Today


 
Categories Question details Back To List
Question  posted by ljp on May 18, 2009 08:43
open dhtmlx forum
Moved columns not saving the correct size

Hi.
When I attempt to use the enableAutoSizeSaving() and enableOrderSaving() methods - the behaviour I se is not as expected.

This is my grid set-up:

    var grid;
    function doInitGrid()
    {
        grid = new dhtmlXGridObject('gridbox');
        grid.setImagePath("codebase/imgs/");
        grid.setHeader("Column 0, Column 1, Column 2, Column 3, Column 4, Column 5, Column 6");
        grid.setInitWidthsP("20,20,20,10,10,10,5");
        grid.setSkin("native");
        grid.enableResizing("true,true,true,true,true,true,true");
        grid.enableAutoHeight(true);            
        grid.init();
        grid.enableColumnMove(true);
        grid.enableAutoSizeSaving();
        grid.enableSortingSaving();
        grid.enableOrderSaving();
        grid.loadXML("step3.xml");
grid.loadSizeFromCookie();
        grid.loadSortingFromCookie();
        grid.loadOrderFromCookie();
        grid.attachEvent("onAfterCMove",function(a,b)
        {
            grid.saveSizeToCookie();
        });
    }
    function restore()
    {
        grid.clearConfigCookie();            
    }

Expected behaviour:
When column 2 is moved over column 3 and then the page reloaded, the columns should retain their initial widths. (20% at index 3 and 10% at index 2)

Actual behaviour:
After the page reload the columns have swapped their widths, column 2 (now index 3) is 10% width and column 3 (now index 2) is 20%.
When the page is reloaded AGAIN, the colums swap widths again; the columns continue to swap widths on every subsequent reload.

Moving column 2 further up the grid, to index 5 or 6 for e.g. causes many columns to swap widths and for every reload each column will have a different width.

Is this an error in my grid set up or a bug?

Thanks for any help, Luke.
Answer posted by Alex (support) on May 18, 2009 09:01

The operations with grid rows can be executed only after data is loaded:

  grid.loadXML("step3.xml",doAfterXMLLoading); 

function doAfterXMLLoading(){
  grid.loadSizeFromCookie(); 
  grid.loadSortingFromCookie(); 
  grid.loadOrderFromCookie();
}

Please, take a look at the sample in the grid package:

dhtmlxGrid/samples/rows_columns_manipulations/pro_column_states_save.html

Answer posted by ljp on May 19, 2009 02:17

Hi, thanks for the reply.

However even using the supplied code the same problem is occuring.

If I remove the loadSizeFromCookie() call from the code, the problem doesn't occur - the columns have their correct size after a reload.

Also if I call loadOrderFromCookie() before loadSizeFromCookie(), again the problem does not occur and the columns have their correct size.

But in either of these cases any other column resizing is not saved.

 

Thanks again, Luke.

 

Answer posted by Support on May 19, 2009 06:29
Sorry for inconvenience, the previous example was not fully correct, the correct order of commands 

grid.loadOrderFromCookie();
grid.loadSizeFromCookie();
grid.loadSortingFromCookie(); 


because all other settings are column depending, order need to be restored first and only after that all other settings of the column.