Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The results you have above are actually sorted by "asc" and not "desc" as you indicated. Either way, I don't think TinySort has multiple attribute sorting built in, so the next best thing would be to just combine the attributes you want to sort.</p> <p>Since the distance is the default sort, I thought it would be best to combine it with a number value from the other attribute. For example, the myfav attribute is set to "1" to indicate that it is true (I'm assuming this, but it seems like your intent). If I stick this one in front of the distance, it's value ends up being higher than the false value of zero - this is opposite of the sort direction you wanted, so I assigned a true value to be "0" instead of "1" and a false value to be "9" instead of "0". I know it sounds confusing, but check this out:</p> <p>Sort by Fav:</p> <pre><code>Location fav been dist combined 1. Joe's Shack 1 0 .08 0.08 2. Mama's 1 1 .15 0.15 3. Hot Dog Stand 0 0 .02 9.02 4. Frick frack 0 1 .10 9.10 </code></pre> <p>Sort by Been There:</p> <pre><code>Location fav been dist combined 1. Frick frack 0 1 .10 0.10 2. Mama's 1 1 .15 0.15 3. Hot Dog Stand 0 0 .02 9.02 4. Joe's Shack 1 0 .08 9.08 </code></pre> <p>I hope that makes it clear... anyway, here is a <a href="http://jsfiddle.net/Mottie/6pTh7/" rel="nofollow">demo</a>, where I made the sort order toggle, and the code I used:</p> <pre><code>var list = $("ul#places&gt;li"), sortit = function(el, att){ $(el).toggleClass('desc'); var combo, order = $(el).is('.desc') ? 'desc' : 'asc'; // make combo attribute if (att !== 'dist') { list.each(function(){ // attr value = 1 means true, so assign it as a zero // attr value = 0 means false, so assign it as a nine // these numbers + distance, makes sure the lower // values are sorted first combo = $(this).attr(att) === '1' ? '0' : '9'; $(this).attr('combo', combo + $(this).attr('dist')); }); att = 'combo'; } list.tsort('',({order:order,attr:att})); }; // Sort by favorite: $('button:contains(Fav)').click(function(){ sortit(this, 'myfav'); }); // Sort by favorite: $('button:contains(Been)').click(function(){ sortit(this, 'beenthere'); }); // Sort by default $('button:contains(Dist)').click(function(){sortit(this, 'dist'); }); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload