Treegrid, filter and footer

Hi again, :slight_smile:



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

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");
});

In case of treegrid it will be #stat_tree_total

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.

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(",

,#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

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

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 )

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.


The code snippet above need to be applied when grid loaded first time, it can be rewritten in more agnostic way as

grid = new…
grid.attachFooter(",

,#stat_total");
grid.attachEvent(“onXLE”,function(){
var sum=0;
mygrid.forEachRow(function(id){
summ+=mygrid.cells(id,3).getValue()*1;
});
document.getElementById(“some1”).innerHTML=“summ”;
});
… other init…

the code attached to onXLE event will fire when data loaded in grid in any possible way


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

Working sample sent by email.

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.

Similar sample, but for TreeGrid sent by email

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?

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

Perfect!!!

Thank you for your help and patience, :slight_smile:

Charly