I am trying to use tinysort as part of a mobile application that I create using jQuery mobile. My application finds locations near users' locations, and I want to be able to sort the results quickly on the fly without wasting time re-querying db.
So, I want to use tinysort to re-sort the results based on whether the user has a favorite place in the area, and then by distance, in addition, I want to be able to sort by the "beenthere" attribute if the user noted that they were in location.
This is what I want to do: Sort by favorites:
$("ul#places>li").tsort('',({order:"desc",attr:"myfav"},{order:"asc",attr:"dist"}));
Sort by Been There:
$("ul#places>li").tsort('',({order:"desc",attr:"beenthere"},{order:"asc",attr:"dist"}));
Sort by default: // This is easy and does not work without problems:
$("ul#places>li").tsort('',{order:"desc",attr:"dist"});
With default list order, for example:
<ul id="places"> <li myfav="0" beenthere="0" dist=".02">Hot Dog Stand</li> <li myfav="1" beenthere="0" dist=".08">Joe Shack</li> <li myfav="0" beenthere="1" dist=".10">Frick frack</li> <li myfav="1" beenthere="1" dist=".15">Mama's</li> </ul>
Sort by fav should return:
- Joe shack
- Mom's
- Hot Dog Stand
- Freak freck
Sort must be returned:
- Freak freck
- Mom's
- Hot Dog Stand
- Joe shack
Then return the sorting by distance:
- Hot Dog Stand
- Joe shack
- Freak freck
- Mom's
My calls above just don't work with multiple attribute selectors, and my syntax is incorrect, or you cannot sort by multiple criteria.
Any ideas on how I can accomplish this with a solution or another solution is appreciated!