whoasked whoasked - 1 year ago 45
Javascript Question

DataTables pagination differs between initial load and selecting number per page

I'm struggling to get DataTables to display the same pagination behaviour on initial load as when a user selects a number of results per page.
When first rendered to screen it looks ok, with e.g. 25 results on the page, but on clicking another page number it goes from e.g.

"Showing 1 to 025 of 301 entries"


Showing 26 to 301 of 301 entries

So rather than showing just the next 25 results on page 2 it's showing ALL those except the first 25. If I choose a number of rows per page from the drop down menu this behaviour corrects itself and I see the 25 results per page I'd expect.

I've had a good look around and for all I can tell the option that should sort this is e.g.:

pageLength: "25"

But I'm using this already. Please see JSFiddle: https://jsfiddle.net/Ly4qnfs5/4/

Thanks for any help.

Answer Source

Just remove the quotes from pageLength: 25 making it a number (and not a string)