react-bootstrap-table icon indicating copy to clipboard operation
react-bootstrap-table copied to clipboard

Support Conjunction (&&) as Search Mode

Open CarstenEnglert opened this issue 9 years ago • 5 comments

Currently, two very different search modes are supported:

  1. A very exclusive one, that accepts only rows with the exact searchText contained as-is in any of their cells. (default)
  2. A very inclusive one, that accepts all rows that contain at least one of the whitespace-separated terms in the searchText. (multiColumnSearch: true)

One could argue whether "multiple columns" are any differentiation between these two cases, but that's not my point here. I merely want to point out that for some use cases the (default) option (1) is too strict and the alternative option (2) is not strict enough.

Therefore I propose introducing an additional strictSearch prop opening up the way for four different search modes, i.e. two more options.


I'll demonstrate the difference with a single row as example:

Col1 Col2
A B C

Search modes and whether they would include the above row for the given searchText

case searchText strict && !multiColumn (existing option 1) !strict && !multiColumn strict && multiColumn !strict && multiColumn (existing option 2)
part of the content "A" ✅ ✅ ✅ ✅
whole content "A B" ✅ ✅ ✅ ✅
wrong order "B A" ❌ ✅ ✅ ✅
leading whitespace " A" ❌ ✅ ✅ ✅
trailing whitespace "B " ❌ ✅ ✅ ✅
not in one column "B C" ❌ ❌ ✅ ✅
partially contained "A D" ❌ ❌ ❌ ✅
not contained "D" ❌ ❌ ❌ ❌

CarstenEnglert avatar Apr 05 '17 16:04 CarstenEnglert

PR #1196 is implementing this. Please have a look. 😄

CarstenEnglert avatar Apr 05 '17 16:04 CarstenEnglert

@CarstenWickner, thanks your proposal, I thinks it's a nice feature and I'll spend some time to review your PR. Thanks a lot :)

BTW, A awesome compared table 👍

AllenFang avatar Apr 06 '17 13:04 AllenFang

I'm glad you like the idea. Additionally, I'd be happy to write some unit tests for it. Unfortunately there doesn't seem to be any unit test setup in this project and I was hesitant to just introduce one as part of this feature.

There seems to be at least the beginning of a jest setup with a __test__ folder. How about I just add jest as dev dependency and write some tests for the TableDataStore's _search() function being altered here? As it's already complicated enough, I'd be more confident to have some test coverage and not just an example in the demo list.

CarstenEnglert avatar Apr 06 '17 16:04 CarstenEnglert

Additionally, I'd be happy to write some unit tests for it. Unfortunately there doesn't seem to be any unit test setup in this project and I was hesitant to just introduce one as part of this feature.

Actually, this project is my first repo for practicing React.js about two year ago, so I even didn't write the test, you know just play with React(Free style)... But no idea why this repo become little popular. so if you grap code deeply, you will find the some components are very complicated and they need to being divided as to some sub component for React stateless principle so that it'll be easy to test..

Anyway, you can skip the testing, that is ok for this repo but not ok for software development 👍

AllenFang avatar Apr 06 '17 16:04 AllenFang

Release at v3.2.0, thanks your hard work 👍

AllenFang avatar Apr 16 '17 06:04 AllenFang