Suresh Kamrushi
Suresh Kamrushi

Reputation: 16086

Custom order sorting in Angular

I have a column as color which having data as

"red","blue","white","black","yellow" 

Now I want to sort them like

"yellow","blue","red","white" and "black"

It means I don't need sorting in alphabetical order.

I want it to customized.

Sample Fiddle

just like you do in mysql: ORDER BY FIELD(color,'yellow','blue','red',"white","black")

Upvotes: 1

Views: 78

Answers (1)

dfsq
dfsq

Reputation: 193301

In your case you can implement sorting function like this:

var colors = ['yellow', 'blue', 'red', 'white', 'black'];

$scope.customOrder = function(friend) {
    return colors.indexOf(friend.color);
};  

Demo: http://jsfiddle.net/f5hb9spz/3/

Upvotes: 3

Related Questions