I'm looking for a type of sort behaviour, one that would match a specific category and bring this to the front of the listing. Like a filter would, except without removing other items.
Imagine these category items in an Isotope grid:
- Red
- Green
- Blue
- Red
- Green
- Blue
If I sort by category, it does so alphabetically to show:
- Blue
- Blue
- Green
- Green
- Red
- Red
What I'd like is to float a specific category to the front, e.g. "Green", like so:
- Green
- Green
- Red
- Red
- Blue
- Blue
Is this possible?
I've tried adding a getSortData function for each category like so:
green : function( $elem ) {
var $greenItems = $elem.filter('.green');
var $otherItems = $elem.filter(':not(.green)');
return $greenItems.add($otherItems);
}
// repeat for blue, red, etc
But that didn't work.
This worked for me:
green : function( $elem ) {
var isGreen = $elem.hasClass('green');
return (!isGreen?' ':'');
},
// etc
来源:https://stackoverflow.com/questions/12551662/jquery-isotope-sort-by-category-but-specify-which-comes-first