简体   繁体   中英

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

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

But Expected output is

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

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/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM