Pagination & Search not working
Pagination & Search not working
HipHip
Posts: 4Questions: 1Answers: 0
Hi.
I am using server and use following code to get the accurate results
geting parameter values form dropdown
let dp1= document.getElementById("dp1").value;
let dp2 = document.getElementById("dp2").value;
let paramObjects=
{
"param1": dp1,
"param2": dp2
};
var ListTable = $('#mytable').DataTable(
{
"processing": true,
"serverSide": true,
"ajax":
{
"url" : 'MY URL',
"type": "POST",
"contentType": "application/json",
"data" : function ( d )
{
return JSON.stringify(paramObjects);
},
},
"columns":
[
{ "data": "id" },
{ "data": "name"},
{ "data": "company"},
],
});
I am getting perfect results.
But the problem is, pagination & searching is not working.
All entries are showing on first page i.e. 52
Although default per page is 10 and pagination is showing correct 6 pages to be paginated. But all records are showing on front page.
I have tried several examples provided on this forum. But no luck.
Please help
Answers
The first question is - do you need server side processing?
With server side processing enabled it is the responsibility of the server script to perform paging, searching and sorting operations and return only the rows to be displayed on the page. With page length of 10 the server script should only return 10 rows. Does your server script follow the Server Side Processing protocol?
Kevin
Thank you for your reply. Yes I need server side processing.
Serverside processing with Pagination, searching, filtering works fine. works fine if I removed
Any thoughts over this.
Regards
I don't think using return like that in
ajax.data
will work. Take a look at the function examples in the docs.Kevin
Thankyou for reply. But I am following last function
Submit data as JSON in the request body:
Right missed that one. The problem is likely in your server script. Use the browser's network inspector to verify the proper parameters are sent in the XHR request. If they are correct then its up to your server script to process them.
Kevin
I got these in XHR request
That is the XHR response. You will want to look at the request tab and the parameters sent in the request.
Also note that
draw: 0
is incorrect. This is a sequence number and Datatables starts with 1.0
will not be sent nor expected by Datatables. See the server Side Processing docs for more details. This might be the issue you are seeing.Kevin