Skip to content
This repository has been archived by the owner on Jun 4, 2024. It is now read-only.

case insensitive filtering #545

Closed
chriddyp opened this issue Aug 14, 2019 · 10 comments · Fixed by #893
Closed

case insensitive filtering #545

chriddyp opened this issue Aug 14, 2019 · 10 comments · Fixed by #893
Assignees

Comments

@chriddyp
Copy link
Member

As discussed in https://community.plot.ly/t/case-insensitive-filter-search-for-dash-datatables/26258

@Marc-Andre-Rivet Marc-Andre-Rivet added the dash-type-enhancement New feature or request label Sep 6, 2019
@Marc-Andre-Rivet Marc-Andre-Rivet added this to the Dash vFuture milestone Sep 6, 2019
@dmt0
Copy link
Contributor

dmt0 commented Sep 23, 2019

We can do something similar to what PowerShell is doing - just prefix every operator with a - character to indicate that filtering is case insensitive. So we would have:

-contains
-eq
-=
->
->=
-!=
etc.

Other option would be to introduce one more operator/reserved word, like ci, followed by a space, that would precede the whole string to indicate that filtering is case insensitive.

@alexcjohnson
Copy link
Collaborator

How well-known / widespread is the precedent of - prefix? It seems weird to me, looks almost like it's negating (ie inverting) the operator.

Functionally each insensitive comparison would have to work as a single operator, since it affects both sides of the comparison - so I'd prefer a prefix instead of a separate word. How about the letter i? So icontains, ieq, i>= etc?

@dmt0
Copy link
Contributor

dmt0 commented Sep 24, 2019

I searched the web a bit for any kinds of precedents and all I found was this weird PowerShell thing and something from mysql that wouldn't translate well to our problem. So there doesn't seem to be any standard case operator out there, we are perhaps free to invent one :)

@chriddyp
Copy link
Member Author

Does it make sense to make case insensitive the default?

For =, maybe we could do case sensitive with quotes e.g. "Product" vs product.

That leaves out case insensitive contains operator.

@alexcjohnson
Copy link
Collaborator

I think whatever we do should be more explicit than quoted vs unquoted - anyway when we translate entries in filter inputs into query strings or structures for callbacks to use this distinction will be lost. And if/when we get to more complex semantics, having the case sensitivity determined by the value one one side will be a limitation; it's really an attribute of the operator so should be set by the operator.

Perhaps we could have a column option (with table-wide prop to set the default for all columns) to use case-insensitive comparisons? I'm not sure I'd want it as the default, but perhaps could be convinced.

If we want to give users complete flexibility though, even a column that's set to case-insensitive should have a way to filter the other way, and vice versa. I suppose one way to do this would be to have three flavors of each operator: default (based on the column/table setting), sensitive, and insensitive. Could be contains, scontains, and icontains?

@Marc-Andre-Rivet
Copy link
Contributor

Marc-Andre-Rivet commented Sep 25, 2019

An interesting flexibility we have here imo is that the syntax we come up with can be specifically tailored for the column filters. For example, (s/i/‘’)contain can exist in the full syntax but be expressed through prefixing or appending /i /s in the column filter - or a ui toggle equivalent later. We can translate from one syntax to the other.

@dmt0
Copy link
Contributor

dmt0 commented Oct 7, 2019

Here's what I propose for the UI:

There's an indicator on each column as well as on multi-column filter. The indicator will look like so: Aa and get a border around it whenever the filter is case sensitive.

Multi-column filter is not part of the table, so column indicator will depend on both - global prop and the per-column prop.

So if table is set to case-insensitive - all columns will show that they're case insensitive. Setting one column to case-sensitive will just set that column to be explicitly case-sensitive.

@da-z
Copy link

da-z commented Mar 15, 2021

Any news on this?

@Marc-Andre-Rivet
Copy link
Contributor

@alexcjohnson Revisiting this issue and the accompanying PR #609

The way I see it "sensitive" and "insensitive" filtering are only two of three types of filtering the user may want to use. Insensitive string comparisons is typically done with toUpperCase instead of toLowerCase (https://docs.microsoft.com/en-us/previous-versions/visualstudio/visual-studio-2015/code-quality/ca1308-normalize-strings-to-uppercase?view=vs-2015&redirectedfrom=MSDN) and there are limitations. The third type of comparison is locale-aware comparison which can be done in JS with the polyfill https://github.com/arty-name/locale-index-of for contains and the native localCompare for other cases (has IE11 support: https://caniuse.com/?search=localecompare) and comes in a few variations (see options for https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/localeCompare)

Will tweak the approach slightly to allow supporting this third case in the future but will not try to implement it as part of updating and completing the work started here.

@eddyojb88
Copy link

Can we have an option to set case insensitive search as a default please?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
6 participants