Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 09-25-2012, 05:51 AM   PM User | #1
john6
New Coder

 
Join Date: Sep 2012
Posts: 47
Thanks: 0
Thanked 0 Times in 0 Posts
john6 is an unknown quantity at this point
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?
john6 is offline   Reply With Quote
Old 09-25-2012, 07:04 AM   PM User | #2
devnull69
Senior Coder

 
Join Date: Dec 2010
Posts: 2,245
Thanks: 10
Thanked 531 Times in 525 Posts
devnull69 will become famous soon enough
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.
devnull69 is offline   Reply With Quote
Old 09-25-2012, 07:30 PM   PM User | #3
rnd me
Senior Coder

 
rnd me's Avatar
 
Join Date: Jun 2007
Location: Urbana
Posts: 3,462
Thanks: 9
Thanked 466 Times in 450 Posts
rnd me is a jewel in the roughrnd me is a jewel in the roughrnd me is a jewel in the rough
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 5/13)
STATS (2013/5) HTML5:90.2% MOB:14% IE7:0.5% IE8:8.6% IE9:9.8% IE10:10%
rnd me is offline   Reply With Quote
Old 09-25-2012, 09:20 PM   PM User | #4
devnull69
Senior Coder

 
Join Date: Dec 2010
Posts: 2,245
Thanks: 10
Thanked 531 Times in 525 Posts
devnull69 will become famous soon enough
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
devnull69 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 04:37 PM.


Advertisement
Log in to turn off these ads.