1

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")

1
  • on what basis ? any particular algorithm or custom algorithm for this ? Commented Feb 19, 2016 at 11:52

1 Answer 1

3

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/

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.