Solved

Date Sorter jQuery

Posted on 2014-01-14
5
231 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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
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…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

623 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