Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $('#mytable').DataTable({
- order: [[0, 'desc']],
- rowGroup: {
- startRender: function (rows, group, level) {
- if (level == 0) {
- //need to filter on group because if you do not it will only total what is display on the page
- //if group is spilt between a page it will show wrong total for the group.
- var total = $('#mytable').DataTable()
- .rows()
- .data()
- .filter(function (data, index) {
- return data[0].display == group ? true : false;
- })
- .pluck(3)
- .reduce(function (a, b) {
- return a + Number(b);
- }, 0);
- //rows.count() does not total count in group, only with what is shown on page
- //so use count of group by filtering.
- var count = $('#mytable').DataTable()
- .rows()
- .data()
- .filter(function (data, index) {
- return data[0].display == group ? true : false;
- }).count();
- return $('<tr/>')
- .append('<td>' + group + '</td>')
- .append('<td class="text-right">' + total.toFixed(2) + '</td>')
- .append('<td/>')
- .append('<td>' + count + '</td>')
- .append('<td colspan="6"></td>');
- }
- return $('<tr/>')
- .append('<td colspan="12">' + group + '</td>');
- },
- dataSrc: ['0.display', 1, 2]
- },
- columnDefs: [{
- targets: [1,2],
- visible: false
- }]
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement