0
votes

When I am calling a serverside DataTables search, I get back one item and this is the response of the AJAX call:

{draw: 1, recordsTotal: 1, recordsFiltered: 18,…}
 data: [{...}]
 draw: 1
 recordsFiltered: 18
 recordsTotal: 1

And DataTables recognizes this:

Showing 1 to 10 of 18 entries (filtered from 1 total entries)

This is my current configuration (I'm currently using pipelining as described here: https://datatables.net/examples/server_side/pipeline.html)

var table = $('#table').DataTable({
    "processing": true,
    "serverSide": true,
    "ajax": $.fn.dataTable.pipeline({
        url: '/url',
        pages: 5 // number of pages to cache,
    }),
    "pagingType": "full_numbers",
    "columns": columnData,
    "order": [[1, "desc"]]
});

When I call table.page.info() in the Chrome browser console, I get

{page: 0, pages: 2, start: 0, end: 10, length: 10, …}
end: 10
length: 10
page: 0
pages: 2
recordsDisplay: 18
recordsTotal: 1
serverSide: true
start: 0

Based on the previous information and the fact that Datatables correctly searches, I think my server-side implementation is correct. However, I don't know what is causing Datatables to display two pages instead of one with ten records per page.

2
how can recordsDisplay > totalRecords? - yash
Thanks, that was the problem! - AnimalTesting
Hi @AnimalTesting, i added answer. if it helps, then upvote. - yash

2 Answers

1
votes

hope this help you to understand.

recordsTotal is used to display total records and set pagination for number of records. Datatable has internal function to set pagination based on recordsTotal.

whilerecordsDisplay is used to display records on particular page.

when you click on pagination, for server side it fetch new records based on length and offset.
So, The problem in your code is that you have recordsDisplay is 18, and recordsTotal is 1. which is not possible.

--> it is never possible that recordsDisplay > recordsTotal.

0
votes

After re-checking the server-side code and with the help of yash's comment, I realized I switched the return values of recordsTotal and recordsDisplay.