Your assistance with the following would be appreciated:-
I want to feed some data into a DHTMLX grid using JSON. In your tutorial docs.dhtmlx.com/doku.php?id=dhtm … _from_json you illustrate a format which looks like this:-
var js={
rows:[
{ id:1001,
data:[
“100”,
“A Time to Kill”,
“John Grisham”,
“12.99”,
“1”,
“05/01/1998”] },
{ id:1002,
data:[
“1000”,
“Blood and Smoke”,
“Stephen King”,
“0”,
“1”,
“01/01/2000”] }
]}
grid.parse(js,“json”);
I have experimented with this and it works very well.
My problem is, how do I get my data into that format in the first place?
My data originally comes from a “Redback object” (Rocket U2 Web Designer) although that is unimportant – I format the data into strings into a server C# List<> object (that too can be flexible). I have then experimented with serializing it like this, before copying it across to a Javascript function (using a hidden field):-
JavaScriptSerializer oSerializer = new JavaScriptSerializer();
SerialString = oSerializer.Serialize(lstCSToJSON);
After Serialization it looks like this, which is of course what I would expect a JSON array of objects to look like:-
“[{“Col1”:“this”,“Col2”:“is”,“Col3”:“the”,“Col4”:“first”,“Col5”:“row”,“Col6”:“for test”},{“Col1”:“this”,“Col2”:“is”,“Col3”:“the”,“Col4”:“second”,“Col5”:“row”,“Col6”:“for test”},{“Col1”:“this”,“Col2”:“is”,“Col3”:“the”,“Col4”:“third”,“Col5”:“row”,“Col6”:“for test”}]”
However the grid won’t accept it using grid.parse(variablename, “json”).
How do I convert the second format to the first?
This is how I’ve tried to pass it to the grid:-
var mygridSerialized;
function doInitGridSerialized(SerializedNowInJava1){
mygridSerialized = new dhtmlXGridObject(‘mygrid_container’);
mygridSerialized.attachEvent(“onRowSelect”,doOnRowSelected);
mygridSerialized.setImagePath(“codebase/imgs/”);
mygridSerialized.setHeader(“Col1, Col2, Col3, Col4, Col5, Col6”);
mygridSerialized.setInitWidths(“100,100,100,100,100,100”);
mygridSerialized.setColAlign(“left,left,left,left,left,left”);
mygridSerialized.setSkin(“light”);
mygridSerialized.init();
mygridSerialized.setColSorting(“str,str,str,str,str,str”);
mygridSerialized.setColTypes(“ed,ed,ed,ed,ed,ed”);
mygridSerialized.parse(SerializedNowInJava1,“json”);
}
This is the error message I get:-
Microsoft JScript runtime error: ‘rows.length’ is null or not an object.
Thanks everyone