Isotope collections can be sorted according to set criteria. Sorting is controlled by clickable elements in a sorter group. An Isotope collection may have many sorter groups linked to it.
To create a sorter group, create an element with attribute data-isotope-sorters
. This can be placed anywhere on the page, and does not need to be placed adjacent to the Isotope layout.
When using sorters, the data-isotope-collection
and data-isotope-sorters
elements must have a matching data-isotope-id
attribute. This is what links the two elements, allowing multiple Isotope collections
per page, and multiple sorter groups per collection.
Any element inside the data-isotope-sorters
element with attribute data-sort
and data-sort-selector
is considered a clickable sorter.
Class active
is applied to sorters when clicked, while being removed from all other sorters in the collection.
<ul data-isotope-sorters data-isotope-id="projects-1">
<li>
<span>Example Sorters</span>
</li>
<li data-sort="original-order" data-sort-selector="original-order">
<span>Original Order</span>
</li>
<li data-sort="sortByStarRating" data-sort-selector="[data-star-rating] parseInt" data-sort-ascending="false">
<span>Star Rating</span>
</li>
<li data-sort="sortByLikes" data-sort-selector=".num-likes parseInt" data-sort-ascending="false">
<span>Likes</span>
</li>
</ul>
Built-In Sort Methods
Isotope has two built-in sorting methods. To use these sorting methods, add the following required attributes to your button or link.
Required Attributes |
Description |
data-sort="original-order" data-sort-selector="original-order"
|
This sorts the Isotope items into the original order laid out in HTML. |
data-sort="random" data-sort-selector="random"
|
Randomizes the order of the items with each click. |
Custom Sort Methods
Isotope items can be sorted according to text or data held within the markup of each item. Custom sort methods are defined by the clickable elements in the data-isotope-sorters
<div>
.
Each sort method requires the following two attributes:
- A unique
id
for the sort method, defined by the data-sort
attribute. Eg. "sortByName"
, or "sortByRanking"
.
- A source for the data defined by the
data-sort-selector
attribute. This selector points to an element or attribute which each Isotope item has in common.
Sorting data can be taken from the following sources
Source |
data-sort-selector
|
Text of child element of Isotope items |
A selector which identifies the item. Eg. "span" or ".likes-count"
|
Text of child element of Isotope items parsed as integer
|
A selector which identifies the item with the addition of parseInt directive. Eg. "span parseInt" or ".likes-count parseInt"
|
Text of child element of Isotope items parsed as float
|
A selector which identifies the item with the addition of parseFloat directive. Eg. "span parseFloat" or ".longitude parseFloat"
|
Plain attribute on an Isotope item |
"[src]" , "[href]" , "[alt]" etc. |
Data attribute on Isotope item |
"[data-category]" , "[data-likes]" , "[data-index]" , "[data-ranking]" etc. |
Note: If you are familiar with the Isotope plugin, the data-sort
value is used internally as each key in Isotope's getSortData
configuration option. See documentation for more detail.
Examples
In the following examples, the items will be sorted in ascending order, which is the default. See Sort Ascending / Descending below.
data-sort-selector=".name" // Sort by text of child element with class 'name'.
data-sort-selector=".symbol" // Sort by text of child element with class 'symbol'.
data-sort-selector="[data-category]" // Sort by alphabetic text of the `data-category` attribute.
data-sort-selector=".number parseInt" // Sort by text of child element with class 'number', parsed as an integer.
data-sort-selector=".weight parseFloat" // Sort by text of element with class 'weight', parsed as a float.
For more examples, please see the Isotope Documentation.