How do I modify my code so that it sorts by both data-status and then data-order? ie the desired result is 1,2,3,4
I need to support IE.
You can try this for multiple parameters
$(document.body).on('click', "#sortthem", function(){
var divList = $(".sortme");
divList.sort(multiSort(["status","order"]));
$("#mydivs").html(divList);
});
function multiSort(fields) {
return function (a, b) {
return fields
.map(function (o) {
return $(a).data(o) > $(b).data(o) ? 1 : $(a).data(o) < $(b).data(o) ? -1 : 0 ;
}).reduce(function firstNonZeroValue (el,n) { return el ? el : n }, 0);
};
}
4
3
2
1
Sort them