dhtmlxtreegrid loaded with JSON object

I am trying to load a dhtmlxGridObject using the parse(myJSONObj, “json”) function call. The first column type is “tree”. I am getting an error “Undefined is null or not an object”. The javascript debugger is pointing at “row.image=row.image||(this.cell._attrs[“image”]||“leaf.gif”)” in dhtmlxtreegrid.js.

Does this script support loading from JSON objects?

Original code can’t load treegrid from json ( it works for plain grids only), if you need to load treegrid from JSON - you can try to use optional extension, which adds such functionality
dhtmlx.com/docs/products/kb/inde … rid%20json

This doesn’t seem to solve my problem with the “Undefined is null or not an object” error.  This seems to be related to not having an image attribute or parent attribute expressed in the JSON object.  I’ve attached my sample.  Thanks for your help.
tester.html.zip (1.97 KB)

a) the order of js files incorrect,any extension ( dhtmlxgrid_json ) may be included only after main dhtmlxgrid.js - it not critical but can cause errors during initial loading.
b) the main reason of problem was caused by our sample , link to which was provided, it is a bit wrong ( already updated ) , the json data has next element

data:[
“1000”,
“Blood and Smoke”,
“Stephen King”,
“0”,
“1”,
“01/01/2000”] }, // <= this comma cause problem, just remove it
],
data:[

IE parse such JSON structure incorrectly , which cause an error

Working sample sent by email.


This works perfectly.  Thanks!



One last question.  What would the JSON data look like to dynamically add children to an existing parent in the tree grid?



Thanks,



 


You need to use the same way of init as for dyn. xml loading


grid.kidsXmlFile must point to the server side script, while it named XmlFile - it will accept data in same format as used for initial loading - json in your case )
the json data must contain “xmlkids” property for branches which need to be loaded from server ( same as above , you must not be confused by “xml” in name )

{ id:1002,
xmlkids:true,
data:[
“1000”,
“Blood and Smoke”,
“Stephen King”,
“0”,
“1”,
“01/01/2000”] }




This is what I was looking for:



{ parent:“1003”, rows:[ { id:“s1003”, data:[ “11”, “A Time to Kill”, “John Grisham”, “12.99”, “1”, “05/01/1998”] }]}



It took me a while to figure it out.  This data and the xmlkids:true has allowed me to do what I needed to do.



Thanks very much for all your help!!