Filth
Filth

Reputation: 3228

Jquery Sorting By Price & Alphabetically

So I have this so far:

JSFIDDLE

And I for the life of me cannot figure out why the price will not sort correctly? You will see that "6" appears at the end rather than the start.

Alphabetically works but no clue why price has issues.

Upvotes: 0

Views: 3045

Answers (5)

Loken Makwana
Loken Makwana

Reputation: 3848

As it's sorting price as alpha style it is expected.

Please check this fiddle, I have associated sorting type with this

http://jsfiddle.net/De8Ku/1476/

Upvotes: 1

Paras
Paras

Reputation: 3067

There seems to be a problem when sorting because of the parsing problem due the the dollar sign. I modified your code like this and it worked

var vA = parseInt($(keySelector, a).text().replace("$",''));
        var vB = parseInt($(keySelector, b).text().replace("$",''));

Try this fiddle

Upvotes: 2

aquinas
aquinas

Reputation: 23796

It's because your sort function doesn't know that you want to treat $6 as "6" so it's treating it like a string and sorting it that way. This is crude, but will put you on the right track:

http://jsfiddle.net/De8Ku/1472/

Upvotes: 2

Gabi Barrientos
Gabi Barrientos

Reputation: 1886

This one time I had to create a table sorter plugin in jQuery, and I had to go through the same problem you have now. To be honest, I don't really remember how I solved that problem anymore, but I still have a fiddle of the code i finally used for my website if you're interested.

http://jsfiddle.net/bcnobel/WbWDm/

Upvotes: 1

Related Questions