Clear header, then set header

Hi there,

Thanks for the neat tool, just what I wanted! I am using dhtmlxGrid v.3.0 Standard edition build 110707.

I have my datagrid loading and displaying fine, all looks good. But then I wanted to build a little javascript function to refresh the datagrid from an existing array. Here is my code (mygrid is already initialized properly with 3 columns etc):

function gridreload() { mygrid.clearAll(true); mygrid.setHeader("Anew,Bnew,Cnew"); mygrid.setInitWidths("90,90,90"); mygrid.setColAlign("left,center,center"); mygrid.setColSorting("str,str,int"); mygrid.parse(myjsarray,"jsarray"); }

Simple function, right? Everything works, data cleared and loaded, except that the header line is blank, i.e. its background is coloured but there is no column header cells or text. I’ve even tried moving the setHeader command after the parse command, but no joy.

It seems like it should work, to my simple mind at least. Any ideas anyone?

Cheers,
4Shades

Solved. I simply had to do a mygrid.init(); before parsing the jsarray again.

What that means is that I can potentially do multiple “init()” calls on the same object without ever closing it. This seems somewhat counter-intuitive to me, i.e. I assumed that an object should only be “initialized” once, but could possibly be “refreshed” many times. But there if no “refresh()” method. Just a matter of terminology, but the API functions are not very clear in this respect.

Still, no harm done and it is working very nicely.

Cheers,
4Shades

What that means is that I can potentially do multiple “init()” calls on the same object without ever closing it.

Init command forces applying of the defined configuration to the grid. If grid was initialized - second call will be ignored. In your case - structure of grid was unset by clearAll(true), so grid was in awaiting for grid.init call when new configuration will be defined.

Thanks Stanislav, that’s very clear.