Start Building Professional
Web Apps Today


 
Categories Question details Back To List
Question  posted by Andrew on Sep 25, 2007 16:29
open dhtmlx forum
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"?>

<rows total_count="109">
<userdata id="views">Summary|Risk Summary|What-If Summary|Historic Risk Summary|Historic VaR Summary|Performance Summary</userdata>
<head>
<column type="tree" sort="str" width="150" align="left">Description</column>
<column type="ro" width="50" sort="str" align="right">Gross Exposure</column>
<column type="ro" width="50" sort="str" align="right">Net Exposure</column>
<column type="ro" width="50" sort="str" align="right">NAV</column>
<column type="ro" width="50" sort="str" align="right">VaR (Exponential)</column>
<column type="ro" width="50" sort="str" align="right">VaR/Exposure</column>
<column type="ro" width="50" sort="str" align="right">VaR/NAV</column>
<column type="ro" width="50" sort="str" align="right">Correlation</column>
<column type="ro" width="50" sort="str" align="right">ES (Flat)</column>
<column type="ro" width="50" sort="str" align="right">ES (Exponential)</column>
<column type="ro" width="50" sort="str" align="right">95% Historic ES</column>
<settings>
<colwidth>px</colwidth>
</settings>
</head>
<row id="3HaE" open="1">
<cell image="blank.gif">Multi-Strategy Manager</cell>
<cell>159,891,219</cell>
<cell>70,441,772</cell>
    .
    .
    .

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?

Answer posted on Sep 25, 2007 18:47
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()
    });