Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Sep 2012
    Posts
    47
    Thanks
    0
    Thanked 0 Times in 0 Posts

    class='Sortable' : How to remember users preference?

    Lets say the user sorted a table with data in a certain way, is it possible to store which field is sorted and if its asc/desc order? So next time they visit the page it's sorted in the same way they left it?

  • #2
    Senior Coder
    Join Date
    Dec 2010
    Posts
    2,398
    Thanks
    12
    Thanked 570 Times in 563 Posts
    Yes, it is

    Two possible ways
    - client side storage (Cookie or localStorage)
    - server side storage (e.g. database table or file)

    The server side storage should be preferred if available, because you won't be dependent on client side settings/browsers.

  • #3
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,448
    Thanks
    11
    Thanked 598 Times in 578 Posts
    Quote Originally Posted by devnull69 View Post
    Yes, it is

    Two possible ways
    - client side storage (Cookie or localStorage)
    - server side storage (e.g. database table or file)

    The server side storage should be preferred if available, because you won't be dependent on client side settings/browsers.
    storing presentation meta on the server is preferred?
    pinging a server every time i resort is preferred?
    maintaining a secured server+db is preferable to a one-line localStorage call?
    how would you even store the click reliably; signing in to persist a sort is preferred?
    waking up an idle EDGE/3G connection for 20 seconds to sort a grid is preferred to instantly saving it with no battery impact?
    relying on an internet connection being online is preferred to using something that's available 24/7?
    saddling the 99% of users with cookies/localStorage/js to facilitate the tiny minority with javascript on but cookies/localstorage off is preferable?


    you have some #$%&'ed up preferences me thinks...



    OP:

    all you need to do is set a cookie or localStorage upon the sort click, and upon pageLoad, apply the same click based on the saved value.



    if you can give your headers an id, something like the following script would work:

    Code:
    <th onclick="localStorage.c=this.id; runTableSort('title'); " id="title"> ...
    <th onclick="localStorage.c=this.id; runTableSort('date'); " id="date">...
    Code:
    <script>
    var tag=document.getElementById(localStorage.c);
    if(tag){ tag.onclick(); } </script>
    my site (updated 2014/10/20)
    BROWSER STATS [% share] (2014/9/03) IE7:0.1, IE8:4.3, IE11:9.2, IE9:2.7, IE10:2.6, FF:16.8, CH:47.5, SF:7.8, NON-MOUSE:37%

  • #4
    Senior Coder
    Join Date
    Dec 2010
    Posts
    2,398
    Thanks
    12
    Thanked 570 Times in 563 Posts
    For clarification:

    @OP: You can only guarantee that user settings (whatever they are) are being stored persistently if you store this information server side

    Every browser side storage can be disabled by the user and/or might be unavailable due to browser settings/limitations.

    @rnd_me: I couldn't agree more ... but (lucky me) I still have to deal with IE6 in limited business environments. I wish I could finally forget about it


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •