rayman1104 / ra-data-nestjsx-crud

Data provider which integrates React Admin with NestJS CRUD library
MIT License
100 stars 27 forks source link

Support case-insensitive comparison for filters #26

Closed Brunni closed 2 years ago

Brunni commented 2 years ago

According to nestjsx/crud it supports filter arguments for case-insensitive comparisons for strings:

https://github.com/nestjsx/crud/blob/bbea082a3f0fc7c1be42a79164f41b8449ad2251/packages/crud-request/src/types/request-query.types.ts

CondOperator.CONTAINS_LOW is the filter type

It would be very helpful for searching/filtering on text columns.

Workaround code:

// TODO: This is a "hack" to pass $contL for filters where we want case insensitive search
      if (params.filter.buyer?.name) {
        debugger;
        const {
          buyer: { name: nameFilter },
          ...otherFilters
        } = filter;
        filter = { ...otherFilters, buyer: { ["name" + "||$contL"]: nameFilter } };
      }
jstoeffler commented 2 years ago

@Brunni Can you clarify where you add the workaround? I'd be interested in a similar solution for a different use case.

I use string enums, and I need the $eq operator, but it seems for string this library only uses $cont. It would be great to have an actual way to set this up, I may try to submit a PR later, but I'd be happy with a hack for now.

Brunni commented 2 years ago

Hi! We are now fine with a different solution and can close this ticket now.

We use the filter type directly in the source tag of the filter input: e.g.

const filters = [
  <TextInput source="id||$contL" alwaysOn />,
  <TextInput source="name||$contL" alwaysOn />,
];
ockam commented 1 year ago

Just came across the same issue (need to use a case insensitive filter) and the above suggestion (source="name||$contL") doesn’t appear to work in React-Admin 4 (4.3.3); when I insert pipes in the source props, the input field stop accepting keystrokes.

I tried with <TextInput> and <SearchInput>.

I’ll try to work on a PR, but if you know another workaround, I’m listening. :)