Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Issue in sorting Email Values, using AngularJS custom sort function

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]

like image 316
mulla.azzi Avatar asked Aug 18 '15 13:08

mulla.azzi


1 Answers

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/

like image 144
Erik Avatar answered Oct 15 '22 14:10

Erik