DHTMLXTreeGrid - loading from JSON issues

Hello,

I have successfully loaded a DHTMLXgrid from JSON. I am trying to load into a TreeGrid and group by Month and then by Year, and sum over a number of hours. I have checked and my JSON is valid:

{"rows":[{"id":"2013", "rows": [{"id":"02", "rows": [{"id":"34031", "data": ["2013","02","25/02/2013","10:00","","0"]}], "data":["thisYear", "thisMonth", "x", "x", "x", "x"]},{"id":"03", "rows": [{"id":"34397", "data": ["2013","03","04/03/2013","10:00","11:00","1"]},{"id":"34074", "data": ["2013","03","14/03/2013","10:00","11:30","1.5"]},{"id":"34144", "data": ["2013","03","21/03/2013","10:00","11:30","1.5"]},{"id":"34323", "data": ["2013","03","25/03/2013","10:00","11:30","1.5"]}], "data":["thisYear", "thisMonth", "x", "x", "x", "x"]},{"id":"04", "rows": [{"id":"34496", "data": ["2013","04","11/04/2013","10:00","11:00","1"]}], "data":["thisYear", "thisMonth", "x", "x", "x", "x"]}], "data":["thisYear", "thisMonth", "x", "x", "x", "x"]}]} 

Here is a snippet of code from my js (also, I commented out myGrid1.setMathRound(2) as I got an error that this was not a function):

myGrid1.setHeader("Year, Month, Date, Start, End, Duration"); myGrid1.setInitWidths("50,50,70,70,70,70"); myGrid1.setColAlign("left, left,center,center, center,right"); myGrid1.setColTypes("tree,tree,ro,ro,ro,ed[=sum]"); myGrid1.setColSorting("str,str,str,str,str,int"); //myGrid1.setMathRound(2); myGrid1.init(); myGrid1.setSkin("dhx_skyblue"); var url1 = "getJSON.php; myGrid1.load(url1,"json");

Thanks in advance for any pointers on what I am doing wrong!!

Cheers,

Hello again,

Well, one problem was I didn’t include dhtmlxgrid_json.js. I have now done that and altered my json code a bit. Now, I get “b is undefined” in dhtmlxgrid_json.js and also an error: “this.cell.parentNode.valTag is undefined”. I have checked and my JSON comes up as valid, but maybe it is not in the right format for DHTMLXTreeGrid??

Here is an example of my JSON:

{ "rows": [ { "id": "2013", "rows": [ { "id": "02", "rows": [ { "id": "34031", "data": [ "2013", "02", "25/02/2013", "10:00", "", "0" ] } ] }, { "id": "03", "rows": [ { "id": "34397", "data": [ "2013", "03", "04/03/2013", "10:00", "11:00", "1" ] }, { "id": "34074", "data": [ "2013", "03", "14/03/2013", "10:00", "11:30", "1.5" ] }, { "id": "34144", "data": [ "2013", "03", "21/03/2013", "10:00", "11:30", "1.5" ] }, { "id": "34323", "data": [ "2013", "03", "25/03/2013", "10:00", "11:30", "1.5" ] } ] }, { "id": "04", "rows": [ { "id": "34496", "data": [ "2013", "04", "11/04/2013", "10:00", "11:00", "1" ] } ] } ] } ]

I would like to have a TreeGrid like your “honda, bmw” example (screen shot attached). I would like to have the parent nodes “year” and “month” only have the total hours for the respective child nodes and that is all (ie no ‘date’, ‘start time’ and ‘end time’). I don’t know how to construct and load the correct Json for this.

???

Thanks again!

Cheers!


Actually, your sample “treegrid_sample1.xml” is exactly what I need but I don’t know the correct json format. Apparently, there is something wrong with my json. Instead of “Total” I would have “year” and instead of “CD”, “DVD” it would be “January”, “February” etc. and the “duration” column would be totaled.

I would really appreciate some help as I really don’t know what I am doing wrong…

Thanks again!


I have changed Json and now have this:

[ { "id": "2013", "tree": { "value": "2013" }, "rows": [ { "id": "02", "tree": { "value": "02" }, "rows": [ { "id": "34031", "year": "2013", "month": "02", "date": "25/02/2013", "start": "10:00", "end": "", "duration": "0" } ] }, { "id": "03", "tree": { "value": "03" }, "rows": [ { "id": "34397", "year": "2013", "month": "03", "date": "04/03/2013", "start": "10:00", "end": "11:00", "duration": "1" }, { "id": "34074", "year": "2013", "month": "03", "date": "14/03/2013", "start": "10:00", "end": "11:30", "duration": "1.5" }, { "id": "34144", "year": "2013", "month": "03", "date": "21/03/2013", "start": "10:00", "end": "11:30", "duration": "1.5" }, { "id": "34323", "year": "2013", "month": "03", "date": "25/03/2013", "start": "10:00", "end": "11:30", "duration": "1.5" } ] }, { "id": "04", "tree": { "value": "04" }, "rows": [ { "id": "34496", "year": "2013", "month": "04", "date": "11/04/2013", "start": "10:00", "end": "11:00", "duration": "1" } ] } ] } ]

I have this js:

myGrid1.setHeader("id,year, month, date, start, end, duration"); myGrid1.setInitWidths("50,50,50,70,70,70,70"); myGrid1.setColAlign("left,left,left,center,center, center,right"); myGrid1.setColTypes("ro,tree,tree,ro,ro,ro,ed[=sum]"); myGrid1.setColSorting("int,str,str,str,str,str,int"); //myGrid1.setMathRound(2); myGrid1.init(); myGrid1.setSkin("dhx_skyblue"); var url1 = "getJSON.php; myGrid1.load(url1,"js");

error is:
“TypeError: this.cell.parentNode.valTag is undefined”

Screen shot of what I get below.

Thanks again.


In this JSON id,tree,year,month,date, etc are the ids of the columns of the grid which defined with setColumnIds() method:
docs.dhtmlx.com/doku.php?id=dhtm … tcolumnids

Hi,

Thank you! However, still a problem…I am getting the sum of “duration” and it is not adding up correctly.

Below a screen shot…

Thanks again,


Please, provide your actual json file with the code of the init of your treeGrid.

Here is the json:

[{"id":"2012", "tree": {"value":"2012"}, "rows": [{"id":"12","tree":{"value":"12"}, "rows": [{"id":"33890", "year":"2012","month":"12","date":"21/12/2012","start":"17:00","end":"18:30","duration":"1.5"}]}]},{"id":"2013","tree": {"value":"2013"}, "rows": [{"id":"02","tree":{"value":"02"}, "rows": [{"id":"33929", "year":"2013","month":"02","date":"15/02/2013","start":"14:00","end":"15:30","duration":"1.5"}]},{"id":"03", "tree":{"value":"03"}, "rows": [{"id":"34536", "year":"2013","month":"03","date":"01/03/2013","start":"14:00","end":"15:30","duration":"1.5"},{"id":"34541", "year":"2013","month":"03","date":"15/03/2013","start":"14:00","end":"15:30","duration":"1.5"},{"id":"34344", "year":"2013","month":"03","date":"29/03/2013","start":"14:00","end":"15:30","duration":"1.5"}]},{"id":"04", "tree":{"value":"04"}, "rows": [{"id":"34522", "year":"2013","month":"04","date":"12/04/2013","start":"14:00","end":"15:30","duration":"1.5"}]}]}] 

This is the code to initialize the TreeGrid:

var myGrid1 = dhxAccord.cells("a2").attachGrid(); //myGrid1dhtmlxgrid_json.js.selMultiRows = true; myGrid1.setImagePath("../../DHTMLX/dhtmlxGrid/codebase/imgs/"); myGrid1.setHeader("id,year, month, date, start, end, duration"); myGrid1.setColumnIds("id,year,month,date,start,end,duration"); myGrid1.setInitWidths("50,50,50,70,70,70,70"); myGrid1.setColAlign("left,left,left,center,center, center,right"); myGrid1.setColTypes("ro,tree,tree,ro,ro,ro,ed[=sum]"); myGrid1.setColSorting("int,str,str,str,str,str,int"); myGrid1.setMathRound(1); myGrid1.init(); myGrid1.setSkin("dhx_terrace"); var url1 = "getJSON.php; myGrid1.load(url1,"js");

Below the screen shot:


Thanks again!!

Hi,

I believe the “sum” in the ‘duration’ column is ignoring all rows that are 0.5 or 1.5 to get the totals which is why the sums are incorrect.

?

The issue is confirmed and fixed.
Please, open ticket at support.dhtmlx.com so we can post you the fixed dhtmlxgrid_math.js

Hello,

Thank you, but your system says my “support period has expired”. I have a license, so I don’t know what to do. Can I send you a private message?

Please contact us at support[at]dhtmlx.com and we’ll send you the fix by email.