Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sorting - Remembering? #171

Open
rusrus opened this issue Nov 1, 2016 · 2 comments
Open

Sorting - Remembering? #171

rusrus opened this issue Nov 1, 2016 · 2 comments

Comments

@rusrus
Copy link

rusrus commented Nov 1, 2016

Is it possible to navigate away from a page after sorting, and come back to it with the sorting entact - the way you left it. I am thinking localStorage or maybe cookies ??

@rusrus
Copy link
Author

rusrus commented Dec 19, 2016

Well I have come up with this and it works using the sessionStorage object. Saves the sort column and direction for a session....

Please let me know if there are ways to improve this code...

$(function(){

var table = $("table").stupidtable();// call function

if (sessionStorage.data_column) {  // check if sessionStorage exists

    var thcol1 = sessionStorage.getItem("data_column"); //retrieve sort col
    var thdir1 = sessionStorage.getItem("data_direction"); //retrieve sort dir

    var $th_to_sort = table.find("thead tr th").eq(thcol1); //select sort column
    $th_to_sort.stupidsort(thdir1); //call direction
}

table.bind('aftertablesort', function (event, data) {

    sessionStorage.setItem("data_direction", data.direction); // data.direction - the sorting direction (either asc or desc)
    sessionStorage.setItem("data_column", data.column); // data.column - the index of the column sorted after a click
  });
});

`

@joequery
Copy link
Owner

Thank you for this snippet. I may try to incorporate it into the documentation somehow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants