Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 240
  • Last Modified:

Date Sorter jQuery

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
eporter76
Asked:
eporter76
  • 2
  • 2
1 Solution
 
zzynxSoftware engineerCommented:
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
 
leakim971PluritechnicianCommented:
You have a syntax error here :
$("#tabs").tabs("option"'"selected");
0
 
leakim971PluritechnicianCommented:
Line 5 I see SORT but you're using sort (lowercase)
0
 
zzynxSoftware engineerCommented:
Thanx 4 axxepting
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now