how to have 2 counters?

how to have 2 counters?

gibzgibz Posts: 3Questions: 1Answers: 0
edited August 31 in Free community support

Hello everyone, is there a way to have 2 counters of the selected rows, one per page and another for the total.
Example : "3 rows selected Total : 5 rows selected"
thanks :)

Replies

  • kthorngrenkthorngren Posts: 13,773Questions: 25Answers: 3,242
    edited August 31

    One option is to use infoCallback. In the callback you can use the API to get the count of selected rows for both the page and the total. Use the selector-modifier to limit the rows returned and use the count() API to get the count. Here is an example to get the count of selected rows on the page:

    var selectedOnPage = api.rows( { selected: true, page:'current' } ).count();
    

    You may need to disable the select.info option.

    Kevin

  • gibzgibz Posts: 3Questions: 1Answers: 0
    edited September 1

    Thanks for the answer but I now have 2 other related problems:
    1- I don't have the info "Showing 0 to 0 of 0 entries" anymore.
    2- the counter for the rows of the pages always mentions 0 selected rows even if a row is selected.

    Thanks again!

    Here's my code

    configDT.infoCallback = function( settings, start, end, max, total, pre ) {
    var api = this.api();
    var selectedOnPage = api.rows( { selected: true, page:'current' } ).count();
    return selectedOnPage + ' rows selected';
    }

  • colincolin Posts: 12,600Questions: 0Answers: 2,154

    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.

    Cheers,

    Colin

Sign In or Register to comment.