Calculation in startRender irrespective of pagination (while using the rowGroup)
Calculation in startRender irrespective of pagination (while using the rowGroup)
Working on data tables and everything seems great. I am using the rowGroup and it works great and showing me the grouping properly. Also using startRender to find and show group vice calculations.
My problem is that pagination affects my calculations; if display length is set to 10, and a group have 17 rows, in start render calculation it gives the calculation result of first 10 rows in page one and calculation remaining 7 in next page.
I want to make the calculations irrespective of page, it is needed the calculation done in the all 17 rows under that group
Code I used is given below ..
Any help appreciated!
Thanks In advance ..
var data_table = $('#myTable').DataTable( {
order: [[0, 'asc'], [1, 'asc']],
"displayLength": 25,
rowGroup:{
startRender: function ( rows, group ) {
var clickTotal = rows
.data()
.pluck(3)
.reduce( function (a, b) {
return parseInt(a) + parseInt(b);
});
var ageCTR = rows
.data()
.pluck(5)
.reduce( function (a, b) {
return parseInt(a) + parseInt(b);
});
return $('<tr>')
.append( '<td>'+group+'</td>' )
.append( '<td>'+clickTotal+'</td>' )
.append( '<td>'+ageCTR +'</td></tr>' );
}, dataSrc: [0, 1]
},
columnDefs: [ {
targets: [ 0, 1,5 ],
visible: false
},
{ orderable: false, targets: [2,3,4] } ],
} );
This question has an accepted answers - jump to answer
Answers
Hi @Sangeetha_Nithya ,
This example here should help - it's showing the sums for the Age column for both the group as a whole and what's shown on the current page.
Cheers,
Colin
Thanks a lot @colin
Just as the mentioned example, Using filter() is the key.
My updated sum function is given below, Hope some one will find it helpful.
[Because I used multilevel grouping based on column 0 & column 1,both of those columns are compared to the group value in the filter function.]
@colin @Sangeetha_Nithya you guys solution is working. But if there is multiple item then how I get the total of subgroup of each row group in pagination ?
First Page:
Second Page
In the above example the total is showing correct as per our example. But in my case I should show the total of Country B is 200 (from first and second page) and City value should be 150.
So how I can find a solution for this ?
@middeugger the best way to find a solution is to provide a test case showing an example of what you have so we can understand your code and provide suggestions.
https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case
Kevin
Do you have any example of multiple rowgroup total in pagination ?
I'm not clear what you mean by "in pagination"? Can you expand on that, please. And, as Kevin asked, please can you post a test case of what you've got so far,
Colin