Reputation: 663
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
Reputation: 11
$(function() {
$("#example").DataTable({
"dom": '<lfip><t><ip>',
"info": true
});
});
Upvotes: 1
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
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
Reputation: 8523
You're going to want to take a look at this example.
Use the option paginationType: 'full_numbers'
Upvotes: 0