Start Building Professional
Web Apps Today


 
Categories Question details Back To List
Question  posted by JimNJ72 on Jan 09, 2009 07:02
open dhtmlx forum
Convert Grid to Tree Grid

I have a grid:

<div id="gridbox" style="height:300px;"></div></center>
<script type="text/javascript">
mygrid = new dhtmlXGridObject("gridbox");
mygrid.setImagePath("/javascripts/dhtmlxGrid/codebase/imgs/");
mygrid.setEditable(false);
mygrid.setSkin("modern");
mygrid.setHeader("Date,Project Title,Project Round,Expense Type,Expense Details,Purpose of Expense,Payment Method,Expense Amount,# of Units or Mi/KM Driven,Description");
mygrid.setInitWidthsP("*,*,*,13,13,*,*,5,5,*");
mygrid.setColTypes("ro,ro,ro,ro,ro,ro,ro,ro,ro,ro");
mygrid.setColAlign("left,left,left,left,left,left,left,right,left,left");
mygrid.enableResizing("true,true,true,true,true,true,true,true,true,true");
mygrid.setColSorting("date,str,str,str,str,str,str,int,int,str");
mygrid.enableHeaderMenu();
//mygrid.groupBy(4);
mygrid.init();

//mygrid.enableSmartRendering(true);
</script>
</div>

I add rows to it with a ruby on rails loop in my code using ... mygrid.addRow until the entire dataset is loaded.

I own treegrid and am trying to figure out how to change this to a treegrid thats exactly the same as the grid above except it groups all the items by ExpenseType and totals the Expense Amount for each grouping. The grid was easy to setup but am having problems getting the tree grid to work as described.
Answer posted on Jan 09, 2009 07:50
>>mygrid.addRow until the entire dataset is loaded
Please beware that it is a slowest way to fill grid with data, it may have sense to form js array and use grid.parse(data,"jsarray"); instead of it

>>I own treegrid and am trying to figure out how to change this to a treegrid
Instead of
    grid.addRow(id,"data")
you can use 
    grid.addRow("gr1","type 1")
    grid.addRow("gr2","type 2")
    grid.addRow(id,"data",null,"gr1");

basically - you can create a rows for groups, and for common rows, use group ID as 4th parameter - such row will be added as a child of group row. 

>>the same as the grid above except it groups all the items
You can use grouping feature of grid instead of treegrid
http://dhtmlx.com/docs/products/dhtmlxGrid/samples/extended_modes/pro_group.html?un=1231516925000
Answer posted by JimNJ72 on Jan 09, 2009 08:39
There is not functionality to group the set by one column like in Grid?  Do I have to establish the groupings manually?  I know in Grid I can just use mygrid.groupBy(4) to group by column #4 and don't have to worry about Parent/Child Relationships.  Basically the only other thing I need that I don't think Grid does is to get totals for those groupings.
Answer posted by Support on Jan 09, 2009 10:11
>>There is not functionality to group the set by one column like in Grid
There is no functionality which will convert plain grid to the treegrid automatically.

>>that I don't think Grid does is to get totals for those groupings.
Not in current version, but we have extended version of extension, which can calculate totals for the groups, if you interested - please contact us directly at support@dhtmlx.com