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

DataTable: Empty "globalFilter" doesn't trigger onFilter on lazy mode #6773

Open
matefgo opened this issue Jun 19, 2024 · 3 comments
Open

DataTable: Empty "globalFilter" doesn't trigger onFilter on lazy mode #6773

matefgo opened this issue Jun 19, 2024 · 3 comments
Labels
Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible

Comments

@matefgo
Copy link

matefgo commented Jun 19, 2024

Describe the bug

Hey guys, how are you doing?

I've been experiencing some issues when using globalFilter when DataTable is on lazy mode.

Whenever the value of globalFilter changes, the onFilter is triggered, as expected.
But when the value of globalFilter returns to a falsy value, the onFilter is not triggered.

I dunno if I'm doing something wrong, but the onFilter should trigger event when the value of globalFilter is cleared, as it's returning to its initial state (kinda...).

I'm afraid this can impact solutions done before, like #2777 which has been fixed in #2986.

Isn't the right approach to the useUpdateEffect to consider only if the value of the globalFilter is different than null | undefined?

 useUpdateEffect(() => {
        if (typeof props.globalFilter === "string") { // OR props.globalFilter !== null || props.globalFilter !== undefined) 
            filter(props.globalFilter, 'global', 'contains');
        }
    }, [props.globalFilter]);

I don't know if I'm being stupid, but I'd like to understand if this is exaclty a bug or something.

Sorry for my english and thank you for the attention!

Reproducer

https://stackblitz.com/edit/vitejs-vite-vctmgs?file=src%2FApp.tsx

PrimeReact version

10.6.6

React version

18.x

Language

TypeScript

Build / Runtime

Create React App (CRA)

Browser(s)

Chrome

Steps to reproduce the behavior

  1. Create a DataTable on lazy mode.
  2. Create a state to control globalFilter.
  3. Input values on globalFilter field and then remove the value.

Expected behavior

The onFilter event should trigger when the value globalFilter is an empty string.

@matefgo matefgo added the Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible label Jun 19, 2024
@sja-cslab
Copy link
Contributor

sja-cslab commented Jun 20, 2024

You should update React to 18 and PrimeReact to 10.6.6 soon. Your version released Dec 5, 2022 so try it in PrimeReact 10 and see if that changed.

@matefgo
Copy link
Author

matefgo commented Jun 20, 2024

You should update React to 18 and PrimeReact to 10.6.6 soon. Your version released Dec 5, 2022 so try it in PrimeReact 10 and see if that changed.

Hey, thanks for you response.

I provided a StackBlitz (https://stackblitz.com/edit/vitejs-vite-vctmgs?file=src%2FApp.tsx) which is using the latest PrimeReact and React 18 and the behaviour described can be reproduced.

@matefgo matefgo changed the title DataTable: Empty "globalFilter" doesn't triggers onFilter on lazy mode DataTable: Empty "globalFilter" doesn't trigge onFilter on lazy mode Jun 20, 2024
@matefgo matefgo changed the title DataTable: Empty "globalFilter" doesn't trigge onFilter on lazy mode DataTable: Empty "globalFilter" doesn't trigger onFilter on lazy mode Jun 20, 2024
@sja-cslab
Copy link
Contributor

},
    "node_modules/primereact": {
      "version": "9.5.0",
      [...]

is the version of that stackblitz. You need to npm update.

However I've never used the global filter like that to be honest. Always use a custom input and pass it to filters

If you look at the Docs you'll notice that this works in another way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible
Projects
None yet
Development

No branches or pull requests

2 participants