Date Sorter jQuery

Posted on 2014-01-14
Last Modified: 2014-01-14

Problem:  I have code that should sort products by date in 3 different categories. (time, region, and title)  The problem is the date sorter is not working right.  

The ascend and descend is only working on the current set of results. *****This code was working until I added a Pageination function.  (I have the page only showing 20 results at a time and there are about 80 results broken up into 4 pages (1,2,3,etc.))

I need to have the code sort through all the results not just the first 20.


$('#tabs_sort a').click(function(e) {

				var link = $(this).attr('href');
				var link = $(this).HAScLASS('ASC');
					var SORT = this.hash.substr(1);

				var aProp;
					var bProp;
					var activeTab = $("#tabs").tabs("option"'"selected");
					var list = $("#tabs-"+activeTab);

					if(link.match(/#time/)) {
					list.append(list.children().get().sort(function(a,b) {


							aProp = $(a).find('span.'+sort).text();
							bProp = $(b).find('span.'+sort).text();
							aProp = Date.parse(aProp);
							bProp = Date.parse(bProp);
							return (aProp > bProp ? 1 : aProp < bProp ? -1 : 0) * ( desc ? -1 : 1);

					} else if(link.match(/#region/)) {
					list.append(list.children().get().sort(function(a,b) {


							aProp = $(a).find('span.'+sort).text();
							bProp = $(b).find('span.'+sort).text();
							return (aProp > bProp ? 1 : aProp < bProp ? -1 : 0) * ( desc ? -1 : 1);

					} else if(link.match(/#title/)) {
					list.append(list.children().get().sort(function(a,b) {

							aProp = $(a).find('span.'+sort).text();
							bProp = $(b).find('span.'+sort).text();
							return (aProp > bProp ? 1 : aProp < bProp ? -1 : 0) * ( desc ? -1 : 1);
					$(this).toggleClass('asc', !desc)
						.toggleClass('desc', desc)	
					.siblings().removeClass('asc desc');

Open in new window

Question by:eporter76
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
LVL 37

Accepted Solution

zzynx earned 500 total points
ID: 39779604
Are you sure you want to combine pagination and sorting through ALL the results?

Normally, pagination is introduced in order not to have to query ALL results immediately.
If you need sorting through all results, you have to query them all (to be able to sort them)
Those two requirements clash.
LVL 82

Expert Comment

ID: 39779708
You have a syntax error here :
LVL 86

Expert Comment

ID: 39779775
LVL 82

Expert Comment

ID: 39779899
Line 5 I see SORT but you're using sort (lowercase)
LVL 37

Expert Comment

ID: 39781507
Thanx 4 axxepting

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
In this post we will learn different types of Android Layout and some basics of an Android App.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

710 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question