How to prevent restart of the start param when sorting by column?
How to prevent restart of the start param when sorting by column?
I have a table where I need to sort by any column on any page. So far everything works, except that when I'm on any table page other than the first, when I click a column to sort, it automatically goes to the first page. I need it to sort the data and continue on that same page.
I tried checking the server, but effectively the client always sends the start param as 0 on the GET, no matter where I was on the table. So the server is working as it should.
How can I prevent this behaviour? I find it really unnatural and surprising that this is the default.
In any case, here's the table initialization:
const table = $('#tablonr').DataTable({
stateSave: true,
info: false,
dom: '<"toolbar">frtip',
language: {
url: "//cdn.datatables.net/plug-ins/1.10.16/i18n/Spanish.json"
},
responsive: true,
pagingType: "numbers",
pageLength: 10,
processing: true,
serverSide: true,
ordering: true,
ajax: {
url: "{% url 'my_url'%}",
type: 'GET',
dataSrc: (json) => {
$('#total-changes-div').text(json.recordsFiltered);
return json.data;
},
},
search: false,
searching: false,
});
Answers
Its not default behavior. You can see with this server side processing example that sorting stays on the same page.
Sounds like you are using
draw()
orajax.reload()
somewhere. Both these API's will jump to the first page unless you change that behavior using thepaging
parameter for either API.Can you post a link to your page or a test case so we can see what else is going on in your page when you are sorting?
https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case
Kevin