admin管理员组

文章数量:1410674

I'm trying to get the count of the number of rows on the current dataTables page. If I do this:

alert($('.tableViewer tbody tr').length)

It gives me the a non-accurate row count (I think it adds the current page and the last one?).

Anyway, I'm just trying to get the row count on the page I'm actually on. Does anyone know how to do this?

Here's my delete button:

function fnDelete(elem){
    if (selected.length>0) {
        var c;
        c = confirm('Are you sure you want to delete the selected ${displayTableName}?');
        if (c) {
            // Create delete url from editor url...
            var deleteURL = (urlstr.substring(0, urlstr.lastIndexOf('/') + 1)) + "delete.do";
            alert($('.tableViewer tbody tr').length)
            deleteRecord(deleteURL,selected[0]);

            alert($('.tableViewer tbody tr').length)
            if ( $('.tableViewer tbody tr').length === 1) {
                setTimeout(function() { oTable.fnPageChange('last'); }, 100);
            }
        }
    }
}

I'm trying to get the count of the number of rows on the current dataTables page. If I do this:

alert($('.tableViewer tbody tr').length)

It gives me the a non-accurate row count (I think it adds the current page and the last one?).

Anyway, I'm just trying to get the row count on the page I'm actually on. Does anyone know how to do this?

Here's my delete button:

function fnDelete(elem){
    if (selected.length>0) {
        var c;
        c = confirm('Are you sure you want to delete the selected ${displayTableName}?');
        if (c) {
            // Create delete url from editor url...
            var deleteURL = (urlstr.substring(0, urlstr.lastIndexOf('/') + 1)) + "delete.do";
            alert($('.tableViewer tbody tr').length)
            deleteRecord(deleteURL,selected[0]);

            alert($('.tableViewer tbody tr').length)
            if ( $('.tableViewer tbody tr').length === 1) {
                setTimeout(function() { oTable.fnPageChange('last'); }, 100);
            }
        }
    }
}
Share Improve this question asked Oct 26, 2012 at 17:52 streetlightstreetlight 5,97813 gold badges66 silver badges102 bronze badges 3
  • 1 Is it possible that there are hidden rows? $('.tableViewer tbody tr:visible').length – JoeFletch Commented Oct 26, 2012 at 17:53
  • you are doing the right way actually. inspect your dom elements – Mustafa Genç Commented Oct 26, 2012 at 17:55
  • @JoeFletch -- that was exactly what I was looking for! Thank you very much! If you write it in an answer I'll be sure to pick it as the correct one and upvote you as well. This was driving me crazy! – streetlight Commented Oct 26, 2012 at 17:56
Add a ment  | 

1 Answer 1

Reset to default 6

The tr elements may be on the page, but not visible. Try this!

$('.tableViewer tbody tr:visible').length

本文标签: javascriptGet number of rows on specific datatables pageStack Overflow