...

View Full Version : class='Sortable' : How to remember users preference?



john6
09-25-2012, 06:51 AM
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?

devnull69
09-25-2012, 08:04 AM
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.

rnd me
09-25-2012, 08:30 PM
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:


<th onclick="localStorage.c=this.id; runTableSort('title'); " id="title"> ...
<th onclick="localStorage.c=this.id; runTableSort('date'); " id="date">...



<script>
var tag=document.getElementById(localStorage.c);
if(tag){ tag.onclick(); } </script>

devnull69
09-25-2012, 10:20 PM
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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum