Different behavior between column defs in code and in xml


With both 1.3 and 1.4 Pro, I have a problem when I load tables via XML that wasn’t there when I was doing it in script. When defining the columns in script, everything was as expected. In XML, the grid seems to load and display just fine, but many subsequent operations don’t work or cause errors. Specifically anything that depends on {mygrid}.hdr.rows, such as getColumnCount(), adjustColumnSize(), etc.



The XML looks like (generated by dom4j, tooltip spans removed for clarity…):



<?xml version="1.0" encoding="UTF-8"?>





Summary|Risk Summary|What-If Summary|Historic Risk Summary|Historic VaR Summary|Performance Summary



Description

Gross Exposure

Net Exposure

NAV

VaR (Exponential)

VaR/Exposure

VaR/NAV

Correlation

ES (Flat)

ES (Exponential)

95% Historic ES



px







Multi-Strategy Manager

159,891,219

70,441,772

    .

    .

    .



Code is:



this.grid = new dhtmlXGridObject(this.renderTarget);

this.grid.imgURL = “xgrid/imgs/”;

this.grid.enableAlterCss(“even”, “uneven”);

this.grid.enableRowsHover(true, ‘row-over’);

this.grid.enableColumnMove(true);

this.grid.enableTreeCellEdit(false);

this.grid.loadXML(‘Report/GetReportData?type=’ + renderModel.type);



As said, the thing loads and displays just fine. But soon after:



for (var i = 0; i < len; i++) {

this.grid.adjustColumnSize(i);

}



has no effect, and calls to getColumnCount() fail with ‘this.hdr.rows[0] has no properties’ (FF, Safari gives you the ever-useful ‘null value’).



The samples don’t seem to provide any clue to this (which I assume is my problem…). Any thoughts?



Problem can be caused by async. loading of XML. In normal case next instruction after loadXML command will be executed when XML not loaded yet.


Next will not work
    mygrid.loadXML(‘Report/GetReportData?type=’ + renderModel.type);

    var len=mygrid.getColumnCount() //xml not loaded yet, structure is unknown

you can use onXLE event or next correct syntax

    mygrid.loadXML(‘Report/GetReportData?type=’ + renderModel.type,function(){
        //this code will be called only after XML loading
        var len=mygrid.getColumnCount()
    });