Thursday, 15 January 2015

AngularJs search and ignoring diacritics -



AngularJs search and ignoring diacritics -

my thought have list of words in there lots of diacritics or accents. , illustration instead of writing róse have róse i'd write rose , have róse in results. first of googled it, here in stackoverflow problem partially solved.

but if have array this, check jsfiddle:

$scope.names = [{name: 'jamón', surname: 'géroux'}, {name: 'andrés', surname: 'guérin'}, {name: 'cristián', surname: 'róse'}, {name: 'fernán', surname:'raúlien'}]; };

then solution doesn't work: jsfiddle. , if had, example, custom filter highlight:

<td ng-bind-html="name.name | highlight:search.$"></td>

i've fount out, examples here https://builtwith.angularjs.org have same problem diacritics/accents. , 1 website there http://illicoweb.videotron.com uses "simple technics" javascript function , str.replace.

any ideas on simple , fast solution? without storing 2 tables diacritics/accents , without it.

thanks in advance!

i've updated jsfiddle modifications filter. i've modified filter search total name rather first name demonstrated:

$scope.ignoreaccents = function(item) { if (!$scope.search) homecoming true; var fullname = item.name + ' ' + item.surname; var text = removeaccents(fullname.tolowercase()); var search = removeaccents($scope.search.tolowercase()); homecoming text.indexof(search) > -1; };

this approach should negate need 2 separate tables.

angularjs angularjs-filter

No comments:

Post a Comment