question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Filter collection items with a string contains instead of equal

See original GitHub issue

I’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:closed
  • Created 2 years ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
jr01commented, Aug 19, 2021

@ghiscoding I’ll migrate to 3.x first and will then create an issue or PR on the new repo.

1reaction
jr01commented, Jul 15, 2021

The try statement consists of a try-block, which contains one or more statements. {} must always be used, even for single statements. At least one catch-block, or a finally-block, must be present. This gives us three forms for the try statement: try…catch try…finally try…catch…finally

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/try...catch

Read more comments on GitHub >

github_iconTop Results From Across the Web

Filtering Items Using a String Comparison - Microsoft Learn
The string comparison that Jet filters support is limited to an equivalence matching. You can filter items based on the value of a...
Read more >
Filter array of objects whose any properties contains a value
I'm wondering what is the cleanest way, better way to filter an array of objects depending on a string keyword . The search...
Read more >
What is the difference between the filter "contains" and "is ...
The expression "contains" retrieves all the values containing at least the given string. For example by filtering the dimension Page : mceclip7.
Read more >
How to perform Contains() search in PowerApps Canvas Apps
You want to filter datasets if a column contains specific text; You want to filter datasets if a column contains a specific value...
Read more >
Liquid filters: array filters - Shopify.dev
The size of a string is the number of characters that the string includes. The size of an array is the number of...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found