I am using the jQuery tablesorter plugin. I am wanting to store how a user has sorted the table on the page and automatically sort that way the next time the page loads. To do this, I first need to be able to find the sortList object that stores how the table is sorted. For the life of me I cannot figure out how to get it. The documentation doesn't seem to have anything on this and I've tried everything I can think of.
In its most basic case you have to include the library and then call a method, called tablesorter (), to provide the possibility to sort the data of a table. Finally, this plugin has extensive documentation that will help you in handling most of the situations you may encounter in your projects.
Given a list of elements, The task is to sort them alphabetically and put each element in the list with the help of jQuery. jQuery text () Method: This method set/return the text content of the selected elements. If this method is used to return content, it provides the text content of all matched elements (HTML tags will be removed).
HTML provides an element for tabular data that, not surprisingly, is called table. The problem with it is that this element doesn’t have an API that allows you to sort its rows based on a certain criteria, such as the price from low to high.
This list contains DOM elements (not jQuery objects of each table header cell like the $headers variable) and is how the original version of tablesorter stored these objects. It is not used in the current version of tablesorter, and is only left in place for backwards compatibility with widgets written for the original tablesorter plugin.
You need to bind your table element to the tablesorter sortEnd
event. All the data for that object is passed in to the handler. You can then get the current sort like so:
var currentSort;
$("#yourtableId").tablesorter({
// initialization
}).bind("sortEnd", function(sorter) {
currentSort = sorter.target.config.sortList;
});
It might be a bit less overhead to save the last sort only when you need it like this:
lastSortList=$("#mytable")[0].config.sortList;
Remember to declare the variable in the right scope of course.
(I think the questioneer's problem probably was that he had to get the DOM element via [0]
and not the jQuery element.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With