Loading native json format into dhtmlxGrid

Hello,

Actually, I’m trying to load native JSON data into a dhtmlxGrid, but in vain.
Knowing that I’ve followed the instruction from the link below
docs.dhtmlx.com/grid__data_forma … jsonformat

Here is the error I got:
Uncaught TypeError: undefined is not a function dhtmlx.js:9
window.dhx4.ajax._call dhtmlx.js:9
window.dhx4.ajax.get dhtmlx.js:9
dhtmlXGridObject.load dhtmlx.js:9
dhtmlXGridObject.load dhtmlx.js:9
doOnLoad gridJSON.html:28
onload gridJSON.html:32

You can find attached an example for those who want to reproduce the problem.
Can you please take a look ? see If someone has already faced this issue.

Thanks
dhtmlxGridJSON.7z (359 KB)

I add some details to better explain the problem.
The code that causes the problem is this:
var data = {“total_count”:50000, “pos”:0, “data”:[
{ “col1”: “A Time to Kill”,
“col2”: “John Grisham”,
“col3”: “100”
},
{ “col1”: “Blood and Smoke”,
“col2”: “Stephen King”,
“col3”: “1000”
},
{ “col1”: “The Rainmaker”,
“col2”: “John Grisham”,
“col3”: “-200”
}
]};
var myGrid;
function doOnLoad(){
myGrid = new dhtmlXGridObject(‘gridbox’);
myGrid.setColumnIds(“col1,col2,col3”);
myGrid.load(data,“js”);
}

The error obtained when the example is deployed on a web server is
Uncaught TypeError: undefined is not a function dhtmlx.js:9
window.dhx4.ajax._call dhtmlx.js:9
window.dhx4.ajax.get dhtmlx.js:9
dhtmlXGridObject.load dhtmlx.js:9
dhtmlXGridObject.load dhtmlx.js:9
doOnLoad gridJSON.html:28
onload gridJSON.html:32

The error obtained by opening the page directly through the browser
TypeError: c.indexOf is not a function
…1)}}}if(a==“GET”&&this.cache!=true){c+=(c.indexOf("?")>=0?"&":"?")+“dhxr”+new Da…

To load data from local array or local object you need to use the parse command

myGrid.parse(data,"js");

Also, you will need to add code that will define initial set of columns and their configuration ( myGrid.setHeader, etc. )

Following the example I’ve seen and test, parse method work only with Basic JSON format, like this :
data={
rows:[
{ id:1, data: [“A Time to Kill”, “John Grisham”, “100”]},
{ id:2, data: [“Blood and Smoke”, “Stephen King”, “1000”]},
{ id:3, data: [“The Rainmaker”, “John Grisham”, “-200”]}
]
};

And my need is to use Native JSON format like this :
data= {“total_count”:50000, “pos”:0, “data”:[
{ “col1”: “A Time to Kill”,
“col2”: “John Grisham”,
“col3”: “100”
},
{ “col1”: “Blood and Smoke”,
“col2”: “Stephen King”,
“col3”: “1000”
},
{ “col1”: “The Rainmaker”,
“col2”: “John Grisham”,
“col3”: “-200”
}
]};

Is someone can give me an example of a GRID with Native JSON format?

Thanks :slight_smile:

The next works for me

[code]var data= { “data”:[
{ “col1”: “A Time to Kill”,
“col2”: “John Grisham”,
“col3”: “100”
},
{ “col1”: “Blood and Smoke”,
“col2”: “Stephen King”,
“col3”: “1000”
},
{ “col1”: “The Rainmaker”,
“col2”: “John Grisham”,
“col3”: “-200”
}
]};

myGrid = new dhtmlXGridObject(‘gridbox3’);
myGrid.setImagePath("./codebase/imgs/");
myGrid.setHeader(“1, 2, 3”);
myGrid.setColumnIds(“col1,col2,col3”)
myGrid.setInitWidths(“50,150,120”);
myGrid.init();
myGrid.parse(data, “js”)[/code]