strange dhtmlxGrid dynamic creation exception:this.hdr.row.0

dear,



I use dhtmlxGrid 1.5 in IE7. Because of custom requirement, I need to create dhtmlxGrid dyanmically and encoutered a strange problem :this.hdr.row.0 is null or not an object. My example code is as follow:









when the scripts is running, the exception is thowed: “this.hdr.row.0 is null or not an object” in funtion _prepareRow() code segment “for(var i=0;i<this.hdr.rows[0].cells.length;i++)”.



But if I insert a Settimeout() function to delay to create the second grid object dynamically, Above exception is disappeared and the two grid can display, but the first grid can not work correctly, such as edit,sort. the example code is as follow:











This is why, it let me exhausted, please give me a hand.



Thanks!

















a strange problem :this.hdr.row.0 is null or not an object
such can occur if you are using data related API while grid.init was not called

In your case , problem related to the

$(“test”).innerHTML+='

When you are using += operation against innerHTML, browser reset all existing html elements, and all old DOM element pointers become invalid.

You can change the code to DOM friendly way

var div=document.createElement(“DIV”);
div.id=“gridbox2”;
div.style.cssText=“width:400px;height:250px;background-color:white;overflow:hidden;”;
$(“test”).appendChild(div);