roberthuttinger
roberthuttinger

Reputation: 1194

Secondary Sort on Isotope possible?

Ive go the sort code all figured out, and it is working as expected. Id like the option of a secondary filter.

I have a series like:

<div id="member1" class="sortItem" data-factor="2">
    <span class="name">Jobs</span>
</div>
<div id="member2" class="sortItem" data-factor="2">
    <span class="name">Wayne</span>
</div>
<div id="member3" class="sortItem" data-factor="3">
    <span class="name">Wozniak</span>
</div>

So if I sort on data-factor, I end up with (abbreviated):

+-------------+-------------+
   NAME           FACTOR
+-------------+-------------+
Wozniak         3
Wayne           2
Jobs            2

But what I would like is the secondary sort to always be alphabetical like:

+-------------+-------------+
   NAME           FACTOR
+-------------+-------------+
Wozniak         3
Jobs            2
Wayne           2

and the reverse sort on data-factor (clicked sort button again):

+-------------+-------------+
   NAME           FACTOR
+-------------+-------------+
Jobs            2
Wayne           2
Wozniak         3

Any ideas on how to implement a second sort?

Cheers!

Upvotes: 1

Views: 178

Answers (2)

guideX
guideX

Reputation: 89

Actually, you can sort by multiple things, check out the getSortData examples on isotope website ...

getSortData: {
    sort1: function($elem) {
        return parseInt($elem.attr('data-category-sort1'), 10);
    },
    bywidth: function($elem) {
        return $elem.width();
    },
    byname: function($elem) {
        return $elem.find('.name').text();
    }
    // more...
}

Upvotes: 1

iCollect.it Ltd
iCollect.it Ltd

Reputation: 93561

The sorting methods just return a string or a number that will be sorted alphabetically or numerically.

If you want to combine both, the lowest common denominator is a string.

The the only remaining issue is how to make the numbers sort alphabetically. You can do that by adding leading 0's to pad them out. Depending on the size of your collections, you may need 1, 2 or 3 digits.

e.g.

For 3 digits (up to 1000 elements) Your sort keys then become something like:

003Wozniak
002Jobs
002Wayne

Which will sort the way you intend.

Upvotes: 1

Related Questions