简体   繁体   中英

How to implement filter in strict mode in ng-grid?

I'm Using ng-grid to populate the Data. I'm using the ng-grid internal filter. But its not what i want.

Data is

$scope.myData = [{name: "Moroni", age: 50},
                   {name: "Tiancum", age: 43},
                   {name: "Jacob", age: 27},
                   {name: "Nephi", age: 29},
                   {name: "Enos", age: 34}];

If I search "Moroni" I'm getting the output i needed. But If i search "roni" ( Moroni ) I should not see Moroni name. My question is how can i apply the strict comparison of the key value.

I want the filter should be true only when

filterText == 'Moroni' [ exactly matching the text instead substring ]

In the angular docs for filter: http://docs.angularjs.org/api/ng.filter:filter

You find this under comparator :

true: A shorthand for function(actual, expected) { return angular.equals(expected, actual)}. 
this is essentially strict comparison of expected and actual.

So try filter:filterText:true

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