Problem sorting email values โ€‹โ€‹using AngularJS custom sort function

I have a column in which I show the email of the user, I have a sort function. But the resulting array is not sorted properly.

Sample code here

Any help would be appreciated

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

In the sample code, the [Ascending] sort output is

abc+1@abc.com
abc@abc.com
bac@abc.com

But the expected result

abc@abc.com
abc+1@abc.com
bac@abc.com

+7
javascript angularjs
source share
1 answer

The hint is to use the special sort and cut function of E-Mail with the @ symbol. Otherwise, the whole line will be compared, and @ higher in value than + .

If you only want to match Usernames , everything should be in order. Otherwise, you also need to compare domains before comparing Usernames .

Here is the JS script: http://jsfiddle.net/zjvsu/898/

+2
source share

All Articles