7

I have a column in which i am displaying Email of user, i have added sort functionality to it. But the resultant array is not sorted properly.

Sample code is here

Any help will be appreciated

<ul ng-repeat="user in users | orderBy:'email':false">

In the example code, output of sorting [Ascending] is

[email protected]
[email protected]
[email protected]

But Expected output is

[email protected]
[email protected]
[email protected]

3
  • 1
    Please place all relevant code in the question and provide expected results. What does not sorted properly mean? Demo seems to work Commented Aug 18, 2015 at 13:28
  • 1
    The sorting is quite proper in your code . its sorting alphabetically Commented Aug 18, 2015 at 13:30
  • ['[email protected]','[email protected]','[email protected]'].sort()produces same order. Has nothing to do with angular itself Commented Aug 18, 2015 at 13:41

1 Answer 1

2

The hint is to use a custom sort function and to "cut" the E-Mail at the @ symbol. Otherwise the whole string is going to be compared and @ is higher in value than +.

If you only want to match the Usernames you should be fine. Otherwise you need to also compare the domains, before comparing Usernames.

Here is a JS Fiddle: http://jsfiddle.net/zjvsu/898/

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

2 Comments

I edited your answer to include the JS fiddle link. :-)
Thanks for Feedback and Editing ;) I'm happy that i could help :)

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.