0

I am using Jquery Datatables to achieve search and sort functionality on HTML table <table>.

I have more then 100 rows in <table> and I used iDisplayLength=6 attribute to display on 6 records at the same time and enabled paging functionality for more records.

The problem is: I want to count that how many <tr> in <table> using jquery.

I used follwing code for that but it gives count 6 <tr> always because I used DisplayLength=6. But I want actual count of <tr>

JavaScript

$(document).ready(function () {
  $("#ContentPlaceHolder1_grdRX").dataTable({
         "iDisplayLength": 6,
         "bLengthChange": false,
         "bFilter": true,
         "bInfo": false,
         "bAutoWidth": false 
     });
 });

function getCount() {
    alert($('#ContentPlaceHolder1_grdRX tr').length);
}

How can I get a count of all the rows?

4
  • care to show some working fiddle for us to fiddle with Commented Oct 17, 2014 at 9:39
  • Do you mean the total count of all rows, not just the rows currently displayed? Commented Oct 17, 2014 at 9:41
  • @markpsmith - Yes exactly. I want total count of all rows which is more then 100+ Commented Oct 17, 2014 at 9:44
  • Are you using server-side data? If so, you can use iTotalDisplayRecords Commented Oct 17, 2014 at 10:19

1 Answer 1

2

It looks like DataTables is removing the rows that aren't on the current page from the DOM, so you aren't going to be able to count them with a jQuery selector. You'll have to use the DataTables API, specifically the fnGetHiddenNodes function:

var table = $('##ContentPlaceHolder1_grdRX').dataTable();
             $('#button').click( function () {
             var hidden = table.fnGetHiddenNodes();
             alert( hidden.length +' nodes were returned' ); } );
Sign up to request clarification or add additional context in comments.

2 Comments

Not working... what is fnGetHiddenNodes() ?? is this any built in function for jquery datatables?
datatables.net/plug-ins/api/#fnGetHiddenNodes please go through It may be helpfull for you. Thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.