Hi guys,
i´m working on the tutorial “Dynamic Apps” (docs.dhtmlx.com/tutorials__dynam … index.html), but I want to use a custom data format.
At the moment I´m using the two methods “grid._process_custom_xml” and “grid._process_custom_xml_row” as shown in (docs.dhtmlx.com/grid__data_forma … dataformat) but it seems, that the two methods don´t work with dhtmlx-suite version 4.
Everytime the error “… .doXPath is not a function” appears. Now I want to use the methods xmltop and xpath as shown in (docs.dhtmlx.com/migration__index.html) but I don´t understand the documentation.
How can I transform the following code, so that it works with the newer versions
[code]//rendering a grid in the right layout column
var grid = layout.cells(“d”).attachGrid(); //attaches a chart to a layout’s cell
grid.setImagePath(“codebase/imgs/”); //sets the path to the source images
grid.setHeader(“Teststep, Beschreibung, Bedingung, Testtyp, SN, Value, Family, Confidence”); //sets the columns’ headers
grid.setColTypes(“ro,ro,ro,ro,ro,ro,ro,ro,ro”); //sets the types of columns
grid.setInitWidths(“100,,,150,100,100,100,100”); //sets the initial widths of columns
grid.setColAlign(“center,center,center,center,center,center,center,center”); //sets the horizontal alignment
// Defining the row-level parser
grid._process_custom_xml=function(xml){
this._parsing=true;
var rows = xml.doXPath("//item"); //gets all row elements from XML
for (var i = 0; i < rows.length; i++){
var id = this.getUID(); //XML has no native ids,so custom ids are generated
this.rowsBuffer[i]={ //stores 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]; //stores id reference
}
this.render_dataset(); //forces update of grid's view after data loading
this._parsing=false;
};
// Define cell-level parser
grid._process_custom_xml_row=function(r, xml){
var teststep = this.xmlLoader.doXPath("./teststep", xml)[0]; //gets teststep sub-tag
var versuchsbeschreibung = this.xmlLoader.doXPath("./versuchsbeschreibung", xml)[0]; //gets versuchsbeschreibung sub-tag
var versuchsbedingung = this.xmlLoader.doXPath("./versuchsbedingung", xml)[0]; //gets versuchsbedingung sub-tag
var testtyp = this.xmlLoader.doXPath("./testtyp", xml)[0]; //gets testtyp sub-tag
var seriennummer = this.xmlLoader.doXPath("./seriennummer", xml)[0]; //gets seriennummer sub-tag
var value = this.xmlLoader.doXPath("./value", xml)[0]; //gets value sub-tag
/*
* kann noch nicht berücksichtig werden, da kein einheitliches Format in der "censoring"-Spalte vorhanden, aktuell: l oder "leer"
*/
//var censoring = this.xmlLoader.doXPath("./censoring", xml)[0]; //gets censoring sub-tag
var family = this.xmlLoader.doXPath("./family", xml)[0]; //gets family sub-tag
var confidence = this.xmlLoader.doXPath("./confidence", xml)[0]; //gets confidence sub-tag
var strAr = [
//xml.getAttribute("name"),
teststep.firstChild.data,
versuchsbeschreibung.firstChild.data,
versuchsbedingung.firstChild.data,
testtyp.firstChild.data,
seriennummer.firstChild.data,
value.firstChild.data,
//censoring.firstChild.data, // siehe oben
family.firstChild.data,
confidence.firstChild.data,
];
//sets just a plain array as no custom attributes are needed
r._attrs={};
for (j=0; j < r.childNodes.length; j++) r.childNodes[j]._attrs={};
//finishes data loading
this._fillRow(r, strAr);
return r;
}
grid.init(); //finishes initializing of the grid
grid.load("data/data.xml",function(){ chart.parse(grid,"dhtmlxgrid"); }, "custom_xml"); //populates chart with the grid's data[/code]
Any help appreciated.
Thank you and sorry for typo,
Hannes