Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery tablesorter filter - how to count the filtered rows

I'm using jQuery plug-in jquery-tablesorter-filter. It works great. I have problem when I want to count how many rows after the table is filtered.

$("#tblContainer").tablesorter({
    debug: false,
    sortList: [
        [0, 0]
    ],
    widgets: ['zebra']

}).tablesorterFilter({
    filterContainer: $("#filterBox"),
    filterColumns: [1, 2],
    filterCaseSensitive: false
});

Here's the code to count the filtered rows (rows that are currently on the screen). But it doesn't give me the correct result. It gave the last count of filtered rows instead of the current counts. It always give result with one key stroke behind.

$("#filterBox").keyup(function () {

    var textLength = $("#filterBox").val().length;

    if (textLength > 0) {

        var rowCount = $("#tblContainer tr:visible").length;

        $("#countCourseRow").html(" found " + rowCount);
    } else {
        $("#countCourseRow").html("");
    }

});
like image 734
Narazana Avatar asked Nov 22 '11 11:11

Narazana


1 Answers

What's wrong with the built in events: http://mottie.github.com/tablesorter/docs/example-option-show-processing.html

The example will look like this:

$("#tblContainer").tablesorter({
debug: false,
sortList: [
  [0, 0]
],
widgets: ['zebra']
}).bind('filterEnd', function() {
  $("#countCourseRow").html("");
  $("#countCourseRow").html("found " + $('#myTable tr:visible').length);
});
like image 140
Fredrik Erlandsson Avatar answered Oct 18 '22 11:10

Fredrik Erlandsson