I am trying to replicate the sample code “Filtering in Smart Rendering Mode” of the below Link: dhtmlx.com/docs/products/dht … _srnd.html
I am reading a 1.5Mb XML file with the mygrid.load(“ClientData2”,“custom_xml”) and parsing without any errors.
The grid is showing OK, but if I add the line:
mygrid.attachHeader("#text_filter,#select_filter, ");
I get a error message ‘undefined’ is not an object (valuating ‘a.childNodes[b]’) on Safari Web inspector pointing to dhtmlxgrid.js file. The
I comment the line back and the error message disappears.
I though the XML could be corrupted and then tested the code by reducing the XML file size until it worked. At 20K it all filtered well. However, if I tested the parts I took out separately and they also worked. It seems it all depended on the size of the file.
Is it a bug or limitation on Grid filtering (attachHeader)?
Here is my code:
<link rel="stylesheet" type="text/css" href="codebase/skins/dhtmlxgrid_dhx_skyblue.css">
<script src="codebase/dhtmlxgrid_filter.js"></script>
<script src="codebase/dhtmlxgrid_srnd.js"></script>
<script src="codebase/jquery.js" type="text/javascript"></script>
<script>
var mygrid;
function doInitGrid(){
mygrid = new dhtmlXGridObject('mygrid_container');
mygrid.setImagePath("codebase/imgs/");
mygrid.setHeader("Customer,City,Country");
mygrid.attachHeader("#text_filter,#select_filter, "); //filter
mygrid.setInitWidths("*,150,150");
mygrid.setColAlign("left,right,right");
mygrid.setSkin("light");
mygrid.setColSorting("na,str,str");
mygrid.setColTypes("ro,ro,ro");
mygrid.getCombo(1).put(2, 2); //filter
mygrid.setSkin("dhx_skyblue"); //filter
mygrid.init();
mygrid.enableSmartRendering(true); //filter
mygrid._process_custom_xml=function(xml){
this._parsing=true;
var rows = xml.doXPath("//Client"); // get all row elements from XML
for (var i = 0; i < rows.length; i++){
var id = this.getUID(); // XML doesn't have native ids, so custom ones will be generated
this.rowsBuffer[i]={ // store references to each row element
idd: id,
data: rows[i],
_parser: this._process_custom_xml_row, // cell parser method
_locator: this._get_custom_xml_data // data locator method
};
this.rowsAr[id]=rows[i]; // store id reference
}
this.render_dataset(); // force update of grid's view after data loading
this._parsing=false;
}
mygrid._process_custom_xml_row=function(r, xml){
var name = this.xmlLoader.doXPath("./name", xml)[0]; // get size sub-tag
var city = this.xmlLoader.doXPath("./city", xml)[0]; // get mode sub-tag
var country = this.xmlLoader.doXPath("./country", xml)[0];
var strAr = [
name.firstChild.data,
city.firstChild.data,
country.firstChild.data,
];
if(typeof strAr === 'undefined' || strAr == null) {
strAr = ["erro", "erro", "erro"];
}
r._attrs={};
for (j=0; j < r.childNodes.length; j++) r.childNodes[j]._attrs={};
this._fillRow(r, strAr);
return r;
}
mygrid.load("ClientData2","custom_xml");
}
</script>