Categories | Question details Back To List | ||||||||
dhtmlxtreegrid with folders loaded with JSON object Hi, I am trying to load dhtmlXGridObject('gridbox') using JSON object. I want this tree to have folders (hierarchies) I do not want to use xml at all I have read http://dhtmlx.com/docs/products/kb/index.shtml?cat=search&page=1&q=5299&ssr=yes&s=json%20format and http://www.dhtmlx.com/docs/products/kb/index.shtml?cat=search&page=1&q=5520&ssr=yes&s=json%20tree I tried to load that tree and I get the data in the tree but do not get the children.... I did not quite understand the line { parent:"1003", rows:[ { id:"s1003", data:[ "11", "A Time to Kill", "John Grisham", "12.99", "1", "05/01/1998"] }]} mentioned in http://www.dhtmlx.com/docs/products/kb/index.shtml?cat=search&page=1&q=5520&ssr=yes&s=json%20tree The parent means this row is a child row of a row with id = "1003" or does the inside rows in the line are children (here we have one child "A Time to Kill" of the row with the property parent:"1003" I tried writing such a code and got an error because the row with the property parent:"1003" does not have data. I tried adding data:[] to that row and I got an empty row. Did not get the line of "A Time to Kill" at all. I did not understand how/where to use xmlkids:true and parent property so I played with what I thought makes sense Here is my code var mygrid = new dhtmlXGridObject(el);//'gridbox'); mygrid.selMultiRows = true; mygrid.setHeader("Sales,BookName,Author,int1,int2,date"); mygrid.setInitWidths("150,150,150,150,150,150"); mygrid.setColAlign("right,left,left,left,left,left"); mygrid.setSkin("light"); mygrid.init(); Now the loading part Attemp1: var data={ rows:[ { id:1002, data:["1000", "Blood and Smoke", "Stephen King", "0", "1", "01/01/2000"] }, { id:1003, data:["-200", "The Rainmaker", "John Grisham", "7.99", "0", "12/01/2001"] }, { id:1004, data:["350", "The Green Mile", "Stephen King", "11.10", "1", "01/01/1992"] }, { parent:1005, rows:[ { id:1006, data:[ "11", "A Time to Kill", "John Grisham", "12.99", "1", "05/01/1998"] }]}] } mygrid.parse(data,"json"); // In that option I get an error because the last line does not have data. I tried adding data:[] to that row and I got an empty // row. Did not get the line of "A Time to Kill" Attemp2: - just a guess, did not see it anywhere... var data={ rows:[ { id:1002, data:["1000", "Blood and Smoke", "Stephen King", "0", "1", "01/01/2000"] }, { id:1003, xmlkids:"1", data:["-200", "The Rainmaker", "John Grisham", "7.99", "0", "12/01/2001"] }, { id:1004, data:["350", "The Green Mile", "Stephen King", "11.10", "1", "01/01/1992"] }, { id:1005, image:"folder.gif", open:true, xmlkids:"1", data:["100", "FOLDER", "FOLDER NAMRE", "12.99", "1", "05/01/1998"], rows:[ { parent:1005, id:1006, data:[ "11", "A Time to Kill", "John Grisham", "12.99", "1", "05/01/1998"] }]}] } mygrid.parse(data,"json"); // In that option I get 4 regular (non folder) lines. Did not get the line of "A Time to Kill" THANKS Tali Answer posted by dhxSupport on Apr 06, 2009 03:14 To load TreeGrid via JSON format please check if you have attached dhtmlxgrid_json.js file from the dhtmlxGrid package. JSON format hasn't "parent" attribute. Sample of JSON format attached Attachments (1)
Answer posted by Tali Tsarfat on Apr 06, 2009 04:00 I have added dhtmlxgrid_json.js and changed the loading part to use the sample you have attached,,, but I still get just regular nodes ------------Here is the new code ----- Maybe you can run it and see what am I doing wrong THANKS!!! var data= { mygrid.parse(data,"json"); Answer posted by dhxSupport on Apr 06, 2009 05:28 Your json format is correct and loaded well. Please check if you have column with "tree" type. Sample will be send you by e-mail Answer posted by Tali Tsarfati on Apr 06, 2009 06:33 What is "tree" type? I thought the first row of the above json format (id:1001) is a "tree" because it has a collection of rows inside What is the "sid"? Why does the row collection inside the the first row of the above json format (id:1001) has id and sid which are strings, and other rows has integer ids? Why do the 2 rows in that row collection has the same data ["1000", "Blood and Smoke", "Stephen King", "0", "1", "01/01/2000"] - What does it mean? Are they 2 child rows of the first row (id:1001) ? What should I add and where to see the hierarchies?? THANKS Answer posted by dhxSupport on Apr 06, 2009 07:11 >>What is "tree" type? I thought the first row of the above json format (id:1001) is a "tree" because it has a collection of rows inside JSON format hasn't declaration of columns types. You have do it using setColType() method. >>What is the "sid"? Sorry, this is mistype. Should be "id". >>Why does the row collection inside the the first row of the above json format (id:1001) has id and sid which are strings, and other rows has integer ids If your row's ids are numbers you can set it like integer or like a string. It means id:1001 is equal to id:"1001"; But id:0 != id:"0". If your row id has any string it should be included into the quotes. >>Why do the 2 rows in that row collection has the same data ["1000", "Blood and Smoke", "Stephen King", "0", "1", "01/01/2000"] - What does it mean? Are they 2 child rows of the first row (id:1001) ? Row with id "1001" has children - row with id "s1002" and row with id "1002". That 2 child rows has equal datas. >>What should I add and where to see the hierarchies Your treeGrid initialization should looks like that: <script> var data= { Answer posted by Tali Tsarfati on Apr 06, 2009 07:46 Thanks for that reply! I tried to define the col type as you wrote - mygrid.setColTypes("tree,ed,ed,ed,ch");
THANKS AGAIN!
Answer posted by dhxSupport on Apr 06, 2009 08:38 >>I tried to define the col type as you wrote - mygrid.setColTypes("tree,ed,ed,ed,ch"); and I get an error "Error type: Configuration. Description: incorrect cell type: tree" Please check if you have include dhtmlxtreegrid.js file from the dhtmlxTreeGrid package which is part of PRO version. >>Also I wanted to ask why there are 6 columns in the data for instance ["1000", "Blood and Smoke", "Stephen King", "0", "1", "01/01/2000"] but you refer just to 5 of them in setInitWidths, setColAlign, setColTypes and setColSorting? No matter how much column do you have in the sourse file or variable. Only that columns will be rendered wich have been defined in the setHeader() method. To get sample of treeGrid initialized from the JSON please contact support@dhtmlx.com and provide your ref. number. Answer posted on Apr 06, 2009 09:07 Hi, I found that the problem is that I did not include dhtmlxtreegrid.js THANKS Answer posted by dhxSupport on Apr 07, 2009 02:23 Please contact support@dhtmlx.com and provide sample where this isuue occur including files which you are using to init grid |