azza idz
azza idz

Reputation: 663

jQuery datatables - display row count on table

I have a jQuery datatable on my view and i'm using pagination to display 10, 20, 50 or 100 rows on a single page. I would like to display somewhere on the table row count. So if i have say 400 rows displayed by 10 on each page message would be Showing 1 - 10 of 400 rows. I can't seem to find how to do it.

Solution:

(This event fires up when data is loaded into table, i can get data length and display it where ever i want)

table = $('#MyDataTable').dataTable({
            fnDrawCallback": function (oSettings, json) {
                console.log('Total row count on load - ', table.fnGetData().length);
            },

Upvotes: 5

Views: 21349

Answers (4)

Rajkishore Sahu
Rajkishore Sahu

Reputation: 11

$(function() {
  $("#example").DataTable({
    "dom": '<lfip><t><ip>',
    "info": true
  });
});

Upvotes: 1

azza idz
azza idz

Reputation: 663

Solution:

(This event fires up when data is loaded into table, i can get data length and display it where ever i want)

table = $('#MyDataTable').dataTable({
            fnDrawCallback": function (oSettings, json) {
                console.log('Total row count on load - ', table.fnGetData().length);
            },

Upvotes: 0

Gyrocode.com
Gyrocode.com

Reputation: 58930

You need to set info to true.

$(document).ready(function() {
    $('#example').DataTable( {
        'info': true
    } );
} );

Also if you have defined dom option, make sure there is character i present in the string, for example:

$(document).ready(function() {
    $('#example').DataTable( {
        'dom': 'lfrtip',
        'info': true
    } );
} );

Upvotes: 11

Jack Guy
Jack Guy

Reputation: 8523

You're going to want to take a look at this example. Use the option paginationType: 'full_numbers'

Upvotes: 0

Related Questions