Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MRT_FilterTextInput crash when filter type is multi select and clear empty pill. #453

Closed
1 task done
Toshinaki opened this issue Dec 5, 2024 · 3 comments · Fixed by #455
Closed
1 task done
Assignees
Labels
bug Something isn't working V2 Issue with MRT V2

Comments

@Toshinaki
Copy link

mantine-react-table version

v2

react & react-dom versions

v18

Describe the bug and the steps to reproduce it

When click the empty pill to clear filter, handleClearEmptyFilterChip just set it to an empty string "".
As we can see in handleClear, you have to check the filter type to determine what value to set when clear.

Minimal, Reproducible Example - (Optional, but Recommended)

The bug is quite clear.
I'll provide a codesandbox link if it's really needed.

Screenshots or Videos (Optional)

No response

Do you intend to try to help solve this bug with your own PR?

None

Terms

  • I understand that if my bug cannot be reliably reproduced in a debuggable environment, it will probably not be fixed and this issue may even be closed.
@alessandrojcm alessandrojcm added bug Something isn't working V2 Issue with MRT V2 labels Dec 10, 2024
@alessandrojcm alessandrojcm self-assigned this Dec 10, 2024
@alessandrojcm alessandrojcm linked a pull request Dec 10, 2024 that will close this issue
@Toshinaki
Copy link
Author

@alessandrojcm

Thanks for the fix.

However I can't think of the use cases of other filter functions for 'multi-select' except 'empty' and 'notEmpty', so I set

filterVariant: 'multi-select',
columnFilterModeOptions: ['empty', 'notEmpty']

But when empty or notEmpty mode is selected, the pill can't be unselected anymore.

So here is my workaround:

const handleClearEmptyFilterChip = () => {
  handleClear();
  setColumnFilterFns((prev) => {
    const { [header.id]: _omitted, ...f } = prev;
    if (
      allowedColumnFilterOptions &&
      allowedColumnFilterOptions.length > 0 &&
      allowedColumnFilterOptions.length[0]
    ) {
      if (!['empty', 'notEmpty'].includes(allowedColumnFilterOptions[0])) {
        return { ...f, [header.id]: allowedColumnFilterOptions[0] };
      }
    }
    return { ...f, [header.id]: 'fuzzy' };
  });
};

It's just a workaround so there may be better solutions.

@alessandrojcm
Copy link
Collaborator

@Toshinaki sorry I am not sure I follow? Multi-select could be used with contains too

@Toshinaki
Copy link
Author

@alessandrojcm
So what the default mode should multi-select use? contains? Not fuzzy I think.

But what does contains mean?

Without setting any filter mode,
if I have a column to be a string separated by ",", and selected options "A" and "B" within the filter, does this mean:

  1. "A" and "B": return rows with "A,B[,...]"
  2. "A" or "B": return rows with "A[,...]" or "B[,...]" or "A,B[,...]"

(BTW I'm using custom filters, and my API server does the filtering, and currently I'm using 2 as my API logic)

And does settings the filter mode to contains make any difference to that logic?


To summarize,
we should add contains to the columnFilterModeOptions for multi-select, and set it as default.
And by contains, we could apply any logic we prefer.
Is that right?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working V2 Issue with MRT V2
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants