Column totals of filtered data

Column totals of filtered data

georgeforstergeorgeforster Posts: 21Questions: 9Answers: 1

I have configured the table as per the example here

http://datatables.net/examples/advanced_init/footer_callback.html

Which gives me the total of the current page, and the total of all pages.

When I apply a filter to the table, the total of all pages is still the same. How can I get the total of the filtered pages

This question has an accepted answers - jump to answer

Answers

  • rf1234rf1234 Posts: 2,947Questions: 87Answers: 416
    edited April 2020

    I think you need to add search: applied like this

    / Total over all pages
    total = api
       .column( 4, { search: 'applied' } )
       .data()
       .reduce( function (a, b) {
             return intVal(a) + intVal(b);
        }, 0 );
    

    Edited: search: applied in column()

  • georgeforstergeorgeforster Posts: 21Questions: 9Answers: 1

    Thanks, but that gives me the overall total still

  • rf1234rf1234 Posts: 2,947Questions: 87Answers: 416
    Answer ✓

    Are you sure you used my latest version? The version I had posted before the final one was definitely wrong.

    If "column( 4, { search: 'applied' } )" does not work you would need to filter the rows first before totaling the amount.

    I do this on many occasions and I can reassure you that it works.

    This for example selects all filtered rows:

    table.rows({ search: 'applied' }).select();
    
  • georgeforstergeorgeforster Posts: 21Questions: 9Answers: 1

    Sorry, I missed that you had changed page = "All" to search = "Applied"

    It works now thank you

This discussion has been closed.