Solved

Date Sorter jQuery

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This video teaches viewers about errors in exception handling.
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…

760 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now