Hi i have spent 2 hours looking through SO to find an answer but can't seem to find one, they all sort by 1 factor only here's what i'm trying to do:
Handle sorting of a list of div's by two parameters:
Parameter 1, sortId; Each div#result inside div#results-container has a data attribute called sortId this ranges from 0 to 2 (0, 1, 2). Also inside this div there is a p with class name totalPrice.
Parameter 2, orderBy: ASC / DESC.
Buttons: I have three buttons that should sort these divs by the sortId attribute so:
Button 1 sorts by sortId 0 Button 2 sorts by sortId 1 Button 3 sorts by sortId 2
Then it should also sort the p.totalPrice ASC then if pushed again sort by DESC but still keeping the order of sortId.
I can get it to sort by Price:
value1 = $(a).find('p.totalPrice').text();
value2 = $(b).find('p.totalPrice').text();
value1 = Number(value1.replace(/[^0-9\.]+/g,""));
value2 = Number(value2.replace(/[^0-9\.]+/g,""));
result = (value1 < value2 ? -1 : (value1 > value2 ? +1 : 0));
I just can't figure out how so do it by the sortId also.
UPDATE:
I have created a JSFiddle: https://jsfiddle.net/ngepj78s/
I'm mostly there just the sorting and most probably less clunky code.