I have a problem on a DataTables using pagination with server-side request.
It looks like the number of pagination buttons is not related to my results.
I always have buttons for pages 1, 2, 3, 4, 5, no matter how many results I have.
My DataTables definition:
$('#tableau_reponses').DataTable({
"ajax": {
url: '/my_api/get_reponses_ajax',
type: 'post',
data: formData
},
"paging": true,
"searching": false,
"bProcessing": true,
"serverSide": true,
"ordering": false,
"info": false,
"pagingType": "numbers",
"pageLength": 20,
"lengthMenu": [10, 20, 50, 100],
'order': [[1, 'asc']],
'columnDefs': [
{
'targets': 0,
'orderable': false,
'className': 'dt-body-center',
'render': function (data, type, full, meta){
return '<input type="checkbox" name="id[]" value="' + $('<div/>').text(data).html() + '">';
}
},
{
'targets': 1,
'render': function (data) {
return '<td class="response_state_folder"></td>';
}
}
],
});
On my test environment, I know I have 29 results. My pageLength is set to 20.
So by default, on page 1, I have 20 results. When I select page 2, I have 9 results. So far so good.
But when I select page 3, 4 or 5 (and I shouldn't be able to) I have 0 results.
Why do I have "3, 4, 5" buttons when, with 29 results, I should have only 2 pages?
Of course if I have 142 results I need 8 pages...
I think I'm missing something pretty obvious here...
Thanks for your help!
===== EDIT =====
Following @Ashu's answer, I've managed to get "recordsFiltered" and "recordsTotal" in my response (respectively "20" and "29" in my example). But now, I have only one button (for page 1) where I'm expecting two.
question from:
https://stackoverflow.com/questions/65670924/why-do-i-have-not-necessary-pagination-buttons-with-jquery-datatables