search.dt Event Handler -- Determine the # of Rows in the Results

search.dt Event Handler -- Determine the # of Rows in the Results

WhetDawgWhetDawg Posts: 5Questions: 2Answers: 0

I need to disable buttons on the page whenever a search results in 0 rows being shown.

var tbl = $('#myTable').DataTable();

tbl.on('search.dt', function (e,settings) {
    consoleLog(tbl.rows().length,'# rows'); // How do I determine the # of rows that resulted from the search?
});

Thanks.

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 21,330Questions: 26Answers: 4,951
    Answer ✓

    Use the selector-modifier of { search: "applied" }.

    Kevin

  • WhetDawgWhetDawg Posts: 5Questions: 2Answers: 0
            var tbl = $('#myTable').DataTable();
    
            tbl.on('search.dt', function (e, settings) {
    
                let nRows = tbl.rows({ search: 'none' })[0].length;     // 40
                let nRowsVisible = tbl.rows({ search: 'applied' })[0].length;     // 26
                let nRowsRemoved = tbl.rows({ search: 'removed' })[0].length;     // 14
            });
    

    Thank you!

Sign In or Register to comment.