How to use sum.js to sum column values after column().search is applied.

How to use sum.js to sum column values after column().search is applied.

rdmrdm Posts: 194Questions: 55Answers: 4

I found the link to sum.js. While I found it is correctly giving me the sum of all records in a desired column, I am unable to get the sum of only selected records when applying a column search like this. I do not see this scenario in the code examples. What can I do to achieve the desired outcome?

// Initially, the summary table has a total of 957.
// ** 
// This search command returns the correct set of records
summaryTable.column(1).search(`^${selectedCampusFilter}$`,true).draw;

// This always returns 957 instead of the correct value after applying the search -- 12.
const counts = summaryTable.column(4).data().sum(); 
console.log(counts);

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 21,391Questions: 26Answers: 4,961
    Answer ✓

    See if the selector-modifer of the column() API helps. Probably something like this:

    const counts = summaryTable.column(4, {search:'applied'}).data().sum();
    

    Kevin

This discussion has been closed.