Hi, In my case I was trying to display both the current page total and total page total not working.

Hi, In my case I was trying to display both the current page total and total page total not working.

Dhinesh Sekar RDhinesh Sekar R Posts: 2Questions: 1Answers: 0

footerCallback: function(row, data, start, end, display) {
let api = this.api();

// Remove the formatting to get integer data for summation
let intVal = function (i) {
    return typeof i === 'string'
        ? i.replace(/[\$,]/g, '') * 1
        : typeof i === 'number'
        ? i
        : 0;
};

console.log(api.column(4).data());

// Function to calculate total for a specific column
let calculateTotal = function(columnIndex) {
    return api
        .column(columnIndex)
        .data()
        .reduce((a, b) => intVal(a) + intVal(b), 0);
};

// Calculate totals for columns 4 and 8
let total = calculateTotal(4);
let totalMetal = calculateTotal(8);

// Calculate page totals for columns 4 and 8
let pageTotal = calculateTotal(4, { page: 'current' });
let pageTotalMetal = calculateTotal(8, { page: 'current' });

// Update footer for column 4
api.column(4).footer().innerHTML = pageTotal + ' (Page Total) - ' + total + ' (Total)';

// Update footer for column 8
api.column(8).footer().innerHTML = pageTotalMetal + ' AED ( ' + totalMetal + ' AED Total)';

}

Answers

  • Dhinesh Sekar RDhinesh Sekar R Posts: 2Questions: 1Answers: 0

    I was trying to display both the current page total and total page total in the footer but not working displays only the current page total .. i also tried console(api
    .column(4)
    .data()); it returns only the current page data of ten records only how to solve it ?

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    This example is doing just that. Can you take a look at that and see if it helps?

    If not, we're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.

    Colin

  • kthorngrenkthorngren Posts: 21,299Questions: 26Answers: 4,945
    edited November 2023

    Are you using server side processing (serverSide: true)?

    Kevin

Sign In or Register to comment.