Sort Multidimensional Array By Multiple Criteria
var data = [{ 'priority': '1', 'date': '01.03.2013', 'title': 'Yeah hi' }, { 'priority': '2', 'date': '', 'title': 'Another title' }, { 'priority': '2',
Solution 1:
One possible solution
data.sort(function(a,b) {
if ( parseInt(a.priority) > parseInt(b.priority) )
return 1;
else if ( parseInt(a.priority) < parseInt(b.priority) )
return -1;
else if (a.date > b.date )
return 1;
else if ( a.date < b.date )
return -1;
else if (a.title > b.title )
return 1;
else if ( a.title < b.title )
return -1;
else
return 0;
});
You should change your date field to be some kind of Epox or smth ( you can fix that by yourself ).
Post a Comment for "Sort Multidimensional Array By Multiple Criteria"