Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
907 views
in Technique[技术] by (71.8m points)

jquery - 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

EDIT: SOLUTION

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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:

$('#offersTable').dataTable({
        "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.

See also the documentation: https://datatables.net/blog/2012-01-16


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...