Suscribe to our newsletter & get early
access to new content.
Sorting alphabetically script
Overview
Script to sort from A to Z or the other way around. This script the SelectizeJS library.
<script>
$(function () {
$('select').selectize({
onChange: function(value) {
sortList(this, value);
}
});
function sortList(el, value) {
var community_list = $("#community_list .card__community");
if(value == "atoz") {
community_list.sort(sort_atoz).prependTo('#community_list');
} else if (value == "ztoa") {
community_list.sort(sort_ztoa).prependTo('#community_list');
}
$(".card__community").fadeIn();
$(".load_more").remove();
}
function sort_atoz(a, b) {
return ($(b).data('order')) < ($(a).data('order')) ? 1 : -1;
}
function sort_ztoa(a, b) {
return ($(b).data('order')) > ($(a).data('order')) ? 1 : -1;
}
})
</script>
Copied to clipboard