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
Solved

Date Sorter jQuery

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

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

Suggested Solutions

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.
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

839 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