Solved

Date Sorter jQuery

Posted on 2014-01-14
5
223 Views
Last Modified: 2014-01-14
Experts,

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.

Code:

$('#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) {

$(a).find('span.btf_region').insertAfter($(a).find('span.btf_releasedDate'));
$(b).find('span.btf_region').insertAfter($(b).find('span.btf_releasedDate'));

							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) {

$(a).find('span.btf_releaseDate').insertAfter($(a).find('span.btf_region'));
$(b).find('span.btf_releaseDate').insertAfter($(b).find('span.btf_region'));

							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');
						e.preventDefault();
				});

Open in new window

0
Comment
Question by:eporter76
[X]
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
5 Comments
 
LVL 37

Accepted Solution

by:
zzynx earned 500 total points
ID: 39779604
Remark:
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.
0
 
LVL 82

Expert Comment

by:leakim971
ID: 39779708
You have a syntax error here :
$("#tabs").tabs("option"'"selected");
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 39779775
0
 
LVL 82

Expert Comment

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

Expert Comment

by:zzynx
ID: 39781507
Thanx 4 axxepting
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Bootstrap Form 16 39
Sending ASP to server side 8 31
web page freezes after ajax post 7 46
Strange router problem - can't access hotmail.com 14 50
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

749 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