Search code examples
angularjssortingangularjs-orderby

sort a table with special characters in angularjs


How can I sort an object based on a property when that property contains special characters such as ä,ü,ö in angularjs using orderBy?

For example if I sort the object users based on the name property,

$scope.users = [
 {name:'A', value:'1'},
 {name:'B', value:'2'},
 {name:'Ä', value:'3'},
 {name:'Ü', value:'4'},
 {name:'U', value:'5'}
];

it should return:

{name:'A', value:'1'},
{name:'Ä', value:'3'},
{name:'B', value:'2'},
{name:'U', value:'5'},
{name:'Ü', value:'4'}

Solution

  • Sort order is determined doing a lexicographical sort by comparing Unicode (z: U+005A comes before e: U+0065).
    Have a look at this article which presents two different solutions to your problem.