Burak Karakuş Burak Karakuş - 1 year ago 108
jQuery Question

Datatables - Keeping selected page number after callback

I have a datatable which I should change something on it, for example I want to change the status of a content, but this content is in 3rd page on the table. When I change it, datatable refreshes itself to the 1st page. What I'm trying to do is to keep the selected page number and call it back after refresh. Is that possible?

btw, I'm using datatables 1.9.4


What I've done is simply keeping the page number in every action that I make in datatable and sending it to the Controller and then using it via TempData. If anyone needs a hand about the solution, just make me know, I can explain more detailed.

Answer Source

I save the datatable state in the local storage to avoid passing the page number all over my app. This is how I do it:

        "bStateSave": true,
        "fnStateSave": function (oSettings, oData) {
            localStorage.setItem('offersDataTables', JSON.stringify(oData));
        "fnStateLoad": function (oSettings) {
            return JSON.parse(localStorage.getItem('offersDataTables'));

This is very useful when you go to another page and you want to go back (using the back button) to the last selected page.