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 dhtmlx.com/docs/products/kb/ … son%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


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


data.json (891 Bytes)


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
In the tree I get the 4 nodes and do NOT get the children (which are if I understand correctly
rows:[{ id:‘s1002’, data:[“1000”, “Blood and Smoke”, “Stephen King”, “0”, “1”, “01/01/2000”] },
                    { sid:‘1002’, data:[“1000”, “Blood and Smoke”, “Stephen King”, “0”, “1”, “01/01/2000”] }],
)



------------Here is the new code ----- Maybe you can run it and see what am I doing wrong THANKS!!!



var data= {
    rows:[
            { id:1001,
              rows:[{ id:‘s1002’, data:[“1000”, “Blood and Smoke”, “Stephen King”, “0”, “1”, “01/01/2000”] },
                    { sid:‘1002’, data:[“1000”, “Blood and Smoke”, “Stephen King”, “0”, “1”, “01/01/2000”] }],
              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”] },
            { 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”] }]}




mygrid.parse(data,“json”);


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


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
(I did not get any sample in the mail)



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


>>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:






Thanks for that reply!



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"

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?



 



THANKS AGAIN!



 

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.


Hi,



I found that the problem is that I did not include dhtmlxtreegrid.js
Now that I did, I do not get the error “Error type: Configuration. Description: incorrect cell type: tree” anymore
And I reach the code of dhtmlXGridObject.prototype._process_json of dhtmlxgrid_json.js BUT I get an error when reaching the line this._h2_to_buff
The method is undefined
Can you please assist?



THANKS

Please contact support@dhtmlx.com and provide sample where this isuue occur including files which you are using to init grid

Please make sure you’ve included dhtmlxgrid_json.js