jquery tablesorter issue with page number - tablesorter

I am developing an ASP.NET MVC 4 application using jquery.tablesorter.js, jquery.tablesorter.pager.js and jquery.tablesorter.widget.js. Now I get an issue with this tablesorter, that is, the page number is saved in the local storage.
I understand it is saved for some reasons. The problem is, for example, I last open the 3rd page of the table and leave the session, then re-open a session, it goes to the 3rd page automatically. If, for some reasons, there is not enough items for any item to go to the 3rd page, it simply shows an empty table and pager, and confuses the user.
Any idea is highly appreciated.
Thanks,
A. Zhang

If you don't want the pager to save the page & size, then set the savePages option to false.
If you do want the page to get saved, but you only want to use session storage, then set the storage_useSessionStorage widget option to true.
Please note: the above options only work with my fork of tablesorter.

Related

ASP.NET MVC 4.0 Chrome Caching

I have code in place to disable caching in my MVC application. I'm using the following response headers. They seem to work in all browsers except for Chrome (currently using version 31.0.1650.48). Users are able to submit a form with model values. When they hit the back button I need the page to reload with a blank model. The headers appear to partially work since the request is hitting the action and returning the blank model. However the view isn't updating. The values from the previous post are being retained. I've tried clearing the ModelState but that doesn't work. Any suggestions? Thanks in advance!!
filterContext.HttpContext.Response.Cache.SetExpires(DateTime.UtcNow.AddDays(-1))
filterContext.HttpContext.Response.Cache.SetValidUntilExpires(False)
filterContext.HttpContext.Response.Cache.SetRevalidation(HttpCacheRevalidation.AllCaches)
filterContext.HttpContext.Response.Cache.SetCacheability(HttpCacheability.NoCache)
filterContext.HttpContext.Response.Cache.SetNoStore()
Turning off autocomplete for the form fixed this for me. I appreciate all the input!
<form autocomplete="off"></form>
There is a way to do this in javascript for everything in one go like so...
document.getElementById("YourFormID").reset();
Just add an id to your form and all your inputs will reset on page load. Regardless if its a first time visit or a back button click with the page being cached. The biggest difference from your solution and this is that "the autocomplete attribute is new in HTML5". Which means it is not supported in older browsers, and though it does what you want it also prevents the user from autofilling fields. Meaning that for example on text types inputs users will not see a suggestion of words they may have entered on previous or other pages. You can see an example here.

Displaying survey questions one at a time MVC mobile

I'm trying to develop page for displaying survey questions on a mobile view using mvc. I have to display one question at a time and on clicking next it should display next question.
Am having hard time to achieve this. I initially thought I could using paging, as all the questions are inside a List collection. but then I get struck on how to save the answers selected by user for each questions. From performance side its wise to send a collection back to business layer to save all the selected answers to DB rather than one at a time.
For desktop browser I displayed all the questions on single page and one submit button at the end of the page. So on there is no issue with this one. Problem arises with mobile view.
So could someone please suggest on how to achieve this.
Thanks in advance,
Sai
From performance side its wise to send a collection back to business layer to save all the selected answers to DB rather than one at a time. - i dont think it would be much of a performance issue.
still.there are multiple options for the work you wanna do.
Use cookies as the storage mechanism - this way answers can be stored as key values pairs key being the index of the question.
this way every time you request a new question using ajax via jquery or simpel post back you can you can set cookie to the answer you have got.
save it at server side using session storage same as key value pairs.
use HTML 5 storage.
you can use this to store data at client side using jquery
I would store the questions in a database. Then each user, if the site is accessed via a mobile device (could detect via JavaScript) you would then save a field in their info (in the database) containing the index of the question that they're up to. I think this is a good idea as it would work cross device, if they start on a phone, then move to a tablet, their 'session' will still persist. Then when they're up to the next question, change the index, and query the database using the user's question index for the relevant information to produce the question.

How to cache an entire page save for one element

I'm running an e-commerce website and many pages are dynamic but for a widget displaying the number of items in the visitor's cart. I want to cache the page yet retain this dynamism. I'm considering caching the fragments before and after this widget but I was wondering if there was a simpler way to get this done.
Edit: Perhaps something which decided to give the cached page or not depending on whether the cart was empty or not would be a good start.
Kindest of Regards,
-- Jack
One way to do it is have the cart items displayed using JavaScript that's inserted after the page is loaded. You can see this on places like StackOverflow where your login status gets injected into the page if it wasn't already cached. jQuery can make this pretty straightforward.
You can set the number of items in a cookie accessible to JavaScript, not in the session hash as that's not exposed to the client, and handle that in the document.onload section.

Preserve paging with the DevExpress MVCxGridView control?

I'm working with the 10.2 version of the DevExpress MVC controls. I have a page hosting a MVCxGridView and I need to preserve the current page when navigating away and back to this particular page.
I can see from the old ASPxGridView documentation that there's a PageIndex property, but this seems to only be accessible from a WebForms/Code Behind/Server Control type context. I'm using MVC and can't figure out how to preserve this page setting.
I've tried the cookie settings with the control but those don't seem to persist for me.
Any pointers would be greatly appreciated.
Currently the MVC grid doesnt support SEOFriendly, or at least I cant find anything on it. You might be able to support it yourself using JQuery and perhaps a paging template which redirects the user to the same page adding a paging parameter like ?paging=2. So basically you check if the url has a paging parameter and if so you can tell the grid to GotoPage(paramValue) telling it in this case to start at page 2.
You could get the gridview's page number in the body unload event and then save that value in a cookie. Next time back at the page, in the gridview's init event read the cookie value and set the grid view's page numbe.

mvc and the back button

I'm new to mvc so I don't know if there is a trick to this or not. When a user runs a search on a site I'm building and I take them to the results page, if I click the back button the search form is empty. Is there some way to keep the form fields populated as they were when going back (without resorting to session)? Thanks.
Strange.
Fields should be there by default. What browser are you using?
If you're using a regular browser, then maybe your doing something weird, like, resetting the fields via JavaScript or something. Perhaps elaborating more on your current implementation would help diagnosing your problem?
A last solution would be saving the fields as a cookie and loading them via JavaScript on the forms page inside onLoad.

Resources