DhtmlxGrid init from HTML ,Cookie and Auto column resizing

How to make Auto column resizing and auto save cookie if table init from html ?









            

    

    












            

    

    

        

            

            

        

        

            

            

        

        

            

            

        

        

            

            

        

        

            

            

        

    
Column 1 Column 2
value 11 value 12
value 21 value 22
value 31 value 32
value 41 value 42
value 51 value 52








            








                    Save Width to Cookies


                 Load Width from Cookies

It works nearly the same as in case of normal initialization


window.onload = new function(){

var mygrid = dhtmlXGridFromTable(‘tblToGrid’);             

      mygrid.loadSizeFromCookie(); // load previously save sizes
      mygrid.enableAutoSizeSaving(); // enable size saving after each column resize
}


And what to make Auto column resizing and paginal output  from html table ???

The API is the same as in case of  normal loading

var mygrid = dhtmlXGridFromTable(‘tblToGrid’);             

    mygrid.enablePaging(…
    for (var i=0; i<mygrid.getColumnCount(); i++)
        mygrid.adjustColumnSize(i);


cookie perfectly work in an sampe:





But does not work in:


window.onload = new function(){
var mygrid = dhtmlXGridFromTable('tblToGrid');             
      mygrid.loadSizeFromCookie(); // load previously save sizes
      mygrid.enableAutoSizeSaving(); // enable size saving after each column resize
}



Where an error?

In case of html initialization it is necessary to use cookie name. So, please, try to use the following:

    var mygrid = dhtmlXGridFromTable(‘tblToGrid’);
             
    mygrid.loadSizeFromCookie(“sizes”);

    mygrid.enableAutoSizeSaving(“sizes”);


cookie do not work.



More low I result a code



Where an problem?



--------------------------------- 



DHTML JavaScript Grid samples

 <table width=“100%”  id=“tblToGrid” imgpath="…/imgs/">
     
        Column 1
        Column 2
     
     
        value 11
        value 12
     
     
        value 21
        value 22
     
     
        value 31
        value 32
     
     
        value 41
        value 42
     
     
        value 51
        value 52
     
   
 

 


   



cookie do not work.


More low I result a code


Where an problem?


--------------------------------- 


DHTML JavaScript Grid samples

 
     
       
       
     
     
       
       
     
     
       
       
     
     
       
       
     
     
       
       
     
     
       
       
     
   
Column 1 Column 2
value 11 value 12
value 21 value 22
value 31 value 32
value 41 value 42
value 51 value 52

 

 


   


Try to remove “new” from onload event handler.

The following should work correctly:

window.onload = function(){
var mygrid = dhtmlXGridFromTable(‘tblToGrid’);
for (var i=0; i<mygrid.getColumnCount(); i++)
        mygrid.adjustColumnSize(i);            
      mygrid.loadSizeFromCookie(“sizesx”);
      mygrid.enableAutoSizeSaving(“sizesx”);
}


hm...


ie explorrer:


error in line ...
"sizes" - Definition is absent


 


------

 
window.onload = function(){
var orders_table = dhtmlXGridFromTable('orders_tableID');
for (var i=0; i<orders_table.getColumnCount(); i++)
        orders_table.adjustColumnSize(i);            
     orders_table.loadSizeFromCookie(sizes);  // <-   error line
     orders_table.enableAutoSizeSaving(sizes);
 
        orders_table.setEditable(false);
        orders_table.setSkin("grey");
        orders_table.enableMultiselect(false);
        orders_table.enableAutoHeight;
   //    orders_table.enableColumnAutoSize(true);
   orders_table.enableLightMouseNavigation(true);
 //    orders_table.enableKeyboardSupport(true);
 // orders_table.enableLightMouseNavigation(true);
//  orders_table.enableColumnMove(true);
//  orders_table.enableRowspan(true);
//    orders_table.setInitWidths("150,*,50,80,50,80")
 //  orders_table.attachFooter("�����,#cspan,#cspan,#cspan,#cspan,#cspan,#cspan,#cspan,#cspan,x7000,
0
,-,
0
",["text-align:left;"]);
 // orders_table.setColAlign("left,left,right,right,right,right,right,right,right,right,right,right,right,right,right,right,right");
// orders_table.setColTypes("ro,ro,ro,ro,ro,ro,ro,ro,ro,ro,ro,ro,ro,ro,ro,ro,ro");
 //   orders_table.setColSorting("str,str,int,int,int,int,str,str,str,str,str,str,str,str,str,str,str");
// orders_table.setColumnColor("white,white,#e1ecf7,white,#e1ecf7,white,white,white,white,white,white,white,white,white,white,white,white");
}
    // -->

You missed quotes around sizes

    orders_table.loadSizeFromCookie(sizes);  // <-   missed quotes
     orders_table.enableAutoSizeSaving(sizes);