Categories | Question details Back To List | ||
Treegrid, filter and footer Hi again, :) There is a possibility in footer to show the total summatory of a column (without filter) and a summatory of a filtered rows at the same time? Thanks in advanced Answer posted by Support on Oct 30, 2008 10:04 You can have custom code which will summ vaues in grid and place such value in some cell of footer and use #stat_total to show sum of filtered rows. mygrid.load(url,function(){ var sum=0; mygrid.forEachRow(function(id){ summ+=mygrid.cells(id,3).getValue()*1; }); mygrid.attachFooter(",,"+summ+",#stat_total"); }); Answer posted by Support on Oct 30, 2008 10:05 In case of treegrid it will be #stat_tree_total Answer posted by Carlos Macías on Oct 31, 2008 05:53 Understood. But If I load again the php which generate the treegrid xml when I filter, the treegrid will be loaded twice, isn´t it? Thanks again. Answer posted by Support on Oct 31, 2008 06:47 >>the treegrid will be loaded twice, isn´t it? in case of above code - yes, but you can move attachFooter outside of on-load code mygrid.attachFooter(",,<div id='some1'></div>,#stat_total"); mygrid.load(url,function(){ var sum=0; mygrid.forEachRow(function(id){ summ+=mygrid.cells(id,3).getValue()*1; }); document.getElementById("some1").innerHTML="summ"; }); In such case the footer will be attached only once Answer posted by Carlos Macías on Nov 03, 2008 02:02 Hi, thanks for your last answer. A last problem, the url parameter must have the php which load de hole treegrid, isn't it? Thanks Answer posted by Support on Nov 03, 2008 02:43 Yes, in above scenario - url - path to script|xml, which will load full tree grid. ( it impossible to calculate total value if not all data loaded ) Answer posted by Carlos Macías on Nov 03, 2008 02:51 Sure, but the treegrid had been loaded before at the fist time, then I filter and the treegrid is loaded again. This is what I asked before, the treegrid is loaded twice and the rows are repeated. Answer posted by Support on Nov 03, 2008 04:09 The code snippet above need to be applied when grid loaded first time, it can be rewritten in more agnostic way as Answer posted by Carlos Macías on Nov 03, 2008 07:52 Hi there, I put the code when the grid is loaded first time, but I get that error: c is null dhtmlxtreegrid/dhtmlxgrid.js Line 882 Answer posted by Support on Nov 03, 2008 08:11 Working sample sent by email. Answer posted by Carlos Macías on Nov 03, 2008 09:09 Thanks for your sample, It's exactly how I had uesd it, but that code not work in a treegrid and a filterby function filter. Answer posted by Support on Nov 04, 2008 01:44 Similar sample, but for TreeGrid sent by email Answer posted by Carlos Macías on Nov 04, 2008 06:41 Ok, it works perfectly, but one issue: If I filter in the second column (#text_filter) by 3, the summatory isn't 26.56 (13.28 x 2), but 254.86. The system adds all the rows. It's a bug? Answer posted by Support on Nov 04, 2008 06:48 TreeGrid can use two types of counters #stat_tree_total - sum of all values in column #stat_tree_total_leaf - sum of values on last level only Answer posted by Carlos Macías on Nov 05, 2008 03:01 Perfect!!! Thank you for your help and patience, :) Charly |