dhtmlxGrid cannot pick data from json object

Hi,

I am a newbie at dhtmlxSuite, I have PRO edition, version 4.6.1. What I like about dxtmlGrid is that it is possible to configure the grid via XML file. Here is XML which I use:

[code]

<?xml version="1.0" encoding="UTF-8"?> Name ISO ISO3 px true true true,true,true [/code]

It is equivalent to this code in my controller:

        myGrid.setHeader("Name,ISO,ISO3");
        myGrid.setInitWidths("*,70,70");
        myGrid.setColAlign("left,left,left");
        myGrid.setColTypes("ro,ro,ro");
        myGrid.setColSorting("str,str,str");

I would prefer to use XML for configuring a grid, that would make my controller much lighter. But I encountered a weird issue. If I configure a grid via XML, the grid cannot read data from JSON object. So, this code does not work:

        var data = {"rows":[{"id":1,"data":["Nederland","NL","NLD"]},{"id":2,"data":["Duitsland","DE","DEU"]},{"id":3,"data":["België","BE","BEL"]},{"id":4,"data":["Rusland","RU","RUS"]}]};
        var myGrid = new dhtmlXGridObject('gridbox');
        myGrid.load("app/modules/crm/test/test.xml");
        myGrid.parse(data, "json");

The grid is displayed but without data.

However, if I put JSON data in the file, it works perfectly:

        var myGrid = new dhtmlXGridObject('gridbox');
        myGrid.load("app/modules/crm/test/test.xml");
        myGrid.load("app/modules/crm/test/test.json", "json");

Configuring a grid in the controller also works:

        var data = {"rows":[{"id":1,"data":["Nederland","NL","NLD"]},{"id":2,"data":["Duitsland","DE","DEU"]},{"id":3,"data":["België","BE","BEL"]},{"id":4,"data":["Rusland","RU","RUS"]}]};
        var myGrid = new dhtmlXGridObject('gridbox');
        myGrid.setHeader("Name,ISO,ISO3");
        myGrid.setInitWidths("*,70,70");
        myGrid.setColAlign("left,left,left");
        myGrid.setColTypes("ro,ro,ro");
        myGrid.setColSorting("str,str,str");
        myGrid.init();
        myGrid.parse(data, "json");

Why dhtmlxGrid after loading configuration via XML cannot pick data from JSON object, but pick data perfectly if I place the same object into a.json file and load it via myGrid.load?

I tried to google it out, but found no explanation so far.

Please, try to use the callback function of the load() method:

myGrid.load("app/modules/crm/test/test.xml",function(){ myGrid.parse(data, "json"); });

sematik, thanks! Works like a charm!