0

How to make a custom function to order?

I made this plunker, and noticed that I get an element at a time, which prevents me from ordering the elements of an array. Any idea?

I got to see these two issues, but none helped: angularjs custom sort function in ng-repeat e AngularJS: Custom Sorting Function using OrderBy

1 Answer 1

1

You need to return a value from your function that will be compared against the other values.

For example, it looks like in your plunkr you want to sort by birthday.

You might accomplish this with a function like so:

$scope.customSortFunc = function(person) {
   return new Date(person.birthday);
};

Keeping in mind that different browsers support parsing different date formats so ideally you'd use something like momentjs.

Example Plunkr

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

1 Comment

Thank you @JohnLedbetter. In the case I am using sugar

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.