Filter collection items with a string contains instead of equal
See original GitHub issueI’m submitting a Feature request
Motivation / Use Case
Hi!
My oData backend returns a field that holds a comma delimited string of values: [{ roles: 'User,Sales,SuperUser' }]
.
I’m presenting this in the grid with a formatter that displays each value as a (bootstrap) badge 📛. Nice!
Ultimately I want to be able to search with a (custom) multiselect FilterControl
on any combination of the values.
Now at first I started with a single select and because searching for User
shouldn’t return SuperUser
I added a ,
to the query field and each queried value and use a ‘contains’:
queryFieldFilter: 'concat(roles, \',\')',
filter: {
collection: [
{ value: 'User,', label: 'User' },
{ value: 'Sales,', label: 'Sales' },
{ value: 'SuperUser,', label: 'SuperUser' },
],
operator: OperatorType.contains,
...
This works and $filter=contains(concat(roles, ','), 'User,')
is send to the oData backend. 😀
The next step is to get the multiselect working and I noticed OperatorType.inContains
which sounds like it fits my need, but IN_CONTAINS
isn’t implemented: https://github.com/ghiscoding/Angular-Slickgrid/blob/master/src/app/modules/angular-slickgrid/services/grid-odata.service.ts#L352 😢
Now I’m not completely sure what the purpose of IN_CONTAINS
is and I’m wondering if it can be used and if I can implement it roughly like:
...
else if (operator === 'IN_CONTAINS') {
for (let j = 0, lnj = searchTerms.length; j < lnj; j++) {
const s = odataVersion >= 4 ? `contains(${fieldName}, ${searchTerms[j]})` : `substringof(${searchTerms[j]}, ${fieldName})`;
tmpSearchTerms.push(s);
}
searchBy = tmpSearchTerms.join(' or ');
...
or if there would be a different direction/solution perhaps? 😄
What do you think?
Expected Behavior
IN_CONTAINS
can be used in oData and other backends.
Other Information
Issue Analytics
- State:
- Created 2 years ago
- Comments:8 (5 by maintainers)
Top GitHub Comments
@ghiscoding I’ll migrate to 3.x first and will then create an issue or PR on the new repo.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/try...catch