ODataAngularResources
ODataAngularResources copied to clipboard
Query for search string inside field [Solution]
Here is some solution to search inside field. I.e. we have:
"text": "some TEST here"
We want to get search by text TEST
.
new $odata.Func('startswith','Text', 'TEST')
will return empty, because test
inside string (not on the start). Solution:
-
Set our search field to lowercase:
var lowerFilter = new $odata.Func('tolower', 'Text');
-
Create new function to get index of out search text:
var filterDataIndex = new $odata.Func('indexof', lowerFilter, 'TEST'.toLowerCase());
-
Create new predicate, with filter param (ge 0):
var resultFilter = new $odata.Predicate(filterDataIndex, '>=', 0);
-
Create combination with predicates:
var combination = $odata.Predicate.or([resultFilter]);
-
Send query and get data:
service.filter(combination).query(success)
Thanks! That may help.