Use the filter()
method. If, for example, you wanted to show only items that match "space"
, you would do this:
shuffleInstance.filter('space');
Show multiple groups at once by using an array.
shuffleInstance.filter(['space', 'nature']);
By default, this will show items that match space
or nature
. To show only groups that match space
and nature
, set the filterMode
option to Shuffle.FilterMode.ALL
.
To go back to having no items filtered, you can call filter()
without a parameter, or use Shuffle.ALL_ITEMS
(which by default is the string "all"
).
shuffleInstance.filter(Shuffle.ALL_ITEMS); // or .filter()
You can filter and sort at the same time by passing a sort object as the second parameter.
shuffleInstance.filter('space', {
by: function (element) {
return element.getAttribute('data-title').toLowerCase();
},
});
You can override both Shuffle.ALL_ITEMS
and Shuffle.FILTER_ATTRIBUTE_KEY
if you want.
Shuffle.ALL_ITEMS = 'any';
Shuffle.FILTER_ATTRIBUTE_KEY = 'categories';
Then you would have to use data-categories
attribute on your items instead of data-groups
.