Categories | Question details Back To List | ||||||||
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? Answer posted by Support on Oct 15, 2008 01:59 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 http://dhtmlx.com/docs/products/kb/index.shtml?cat=search&page=1&q=5299&ssr=yes&s=treegrid%20json Answer posted by Ed Palmer on Oct 15, 2008 06:33 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. Attachments (1)
Answer posted by Support on Oct 15, 2008 08:45 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. Answer posted by Ed Palmer on Oct 15, 2008 08:53 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,
Answer posted by Support on Oct 15, 2008 09:15 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 ) Answer posted by Ed Palmer on Oct 16, 2008 08:36 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!! |