Having dataTables_info reflect number of hidden rows

Having dataTables_info reflect number of hidden rows

mesterakmesterak Posts: 6Questions: 0Answers: 0
edited February 2011 in General
I have implemented a filter external to DataTables to hide rows that match specific criterion. However, the dataTables_info block still reports hidden rows in the number of displayed rows as well as in the total rows count. For example, I have 70 total records but 52 of them (TRs) are hidden rows:

[code]
Showing 1 to 70 of 70 entries
[/code]

How would I go about making DataTables ignore hidden rows in the displayed and total row counts?

This is my current initialization of DataTables:

[code]
$('.InfoTable').each(function () {
if ($(this).find('tbody:first > tr').length > 1) {
$(this).dataTable({
"bPaginate": false,
"oSearch": { "sSearch": searchString }
});
}
});
[/code]

Replies

  • allanallan Posts: 63,516Questions: 1Answers: 10,472 Site admin
    You can use fnInfoCallback to override what DataTables puts into the info element ( http://datatables.net/usage/callbacks#fnInfoCallback ). You could do whatever calculations for the row counters you need and display that. Is there a reason you aren't using the filtering options that DataTables provides? A limitation that I could look at addressing in future?

    Allan
  • mesterakmesterak Posts: 6Questions: 0Answers: 0
    I have rows of data that are considered archived. These are identified by the TR having a class name of "archiveItem". I have a checkbox that allows the user to toggle whether archived records (rows) are visible in the table or not. DataTables counts all of the rows where they are visible or not, so the info string shows display and total counts that include the hidden rows. I would like the row counters to ignore the hidden rows when the user unchecks the "Show Archived Items" checkbox.

    I tried to write a custom afnFiltering, but it just isn't working correctly. Of course, my attempt may not be a good one:

    [code]
    $.fn.dataTableExt.afnFiltering.push(
    function (oSettings, aData, iDataIndex) {
    if ($('.InfoTable > tbody').find('tr:eq(' + iDataIndex + ')').is(':hidden'))
    return false;
    else
    return true;
    }
    );

    if ($(this).find('tbody:first > tr').length > 1) {
    $(this).dataTable({
    "bPaginate": false,
    "oSearch": { "sSearch": searchString }
    });
    }

    $('#showArchiveItems').change(function () {

    if ($('.archiveItem:first').is(":hidden")) {
    $('.archiveItem').each(function () {
    $(this).show();
    });
    }
    else {
    $('.archiveItem').each(function () {
    $(this).hide();
    });
    }

    var oTable = $('.InfoTable:first').dataTable();
    oTable.fnDraw();
    });
    [/code]
This discussion has been closed.