Why the number of rows in jquery datatable
(see the code below) is not set to 5? It is equal to 10 8as by default). Why 'iDisplayLength': 5
does not work here?
<script>
function loadData() {
$.getJSON(
'modules/getData.php',
function(data) {
var oTable = $('#newspaper-b').dataTable({
"sPaginationType":"full_numbers",
"aaSorting":[[3, "asc"]],
"bJQueryUI":true,
'iDisplayLength': 5,
'bLengthChange': false
});
oTable.fnDraw();
var list = data.flights;
var textToInsert = '';
for (var i = 0; i < list.length; i++) {
aux = list[i];
textToInsert += '<tr><td>';
textToInsert += aux.Var1;
textToInsert += '</td> </tr>' ;
}
$('table#newspaper-b tbody').html(textToInsert);
}
);
}
</script>
There is a option called pageLength . You can set this for show only 5 entries.
len() method can still be used if you wish to programmatically change the page size and pageLength can be used to specify the initial page length.
The maximum number of rows that a DataTable can store is 16,777,216.
Answer: Use the length Property You can simply use the length property to count or find the number of rows in an HTML table using jQuery. This property can be used to get the number of elements in any jQuery object.
Try something like this. DataTables has built-in options that let you pull data from an AJAX source without trying to build it yourself. Read the documentation and customize it as needed:
function loadData() {
var oTable = $('#newspaper-b').dataTable({
"sAjaxSource": 'modules/getData.php',
"sPaginationType": "full_numbers",
"aaSorting": [
[3, "asc"]
],
"bJQueryUI": true,
'iDisplayLength': 5,
'bLengthChange': false
});
};
To modify the table in some way after the data is loaded, you'll want to add the fnDrawCallback
option:
"fnDrawCallback": function( oSettings ) {
// use jQuery to alter the content of certain cells
$lastcell = $('#newspaper-b').find('tr').find('td:last');
// manipulate it somehow
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With