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

[Data Grid] Make SUBMIT_FILTER_STROKE_TIME editable via props #9157

Closed
2 tasks done
managervcf opened this issue May 30, 2023 · 7 comments · Fixed by #9712
Closed
2 tasks done

[Data Grid] Make SUBMIT_FILTER_STROKE_TIME editable via props #9157

managervcf opened this issue May 30, 2023 · 7 comments · Fixed by #9712
Labels
component: data grid This is the name of the generic UI component, not the React module! feature: Filtering Related to the data grid Filtering feature

Comments

@managervcf
Copy link

Duplicates

  • I have searched the existing issues

Latest version

  • I have tested the latest version

Summary 💡

I would love to be able to control the debounce time on applied filters inside the filterPanel. Currently it's hardcoded here.

Alternatively, please allow users to be able to apply filters manually - via some kind of Apply filters button.

Examples 🌈

No response

Motivation 🔦

This would allow me to optimize the Data Grid with server-side filtering and reduce the amount of unnecessary back-end requests.

Order ID 💳 (optional)

No response

@managervcf managervcf added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label May 30, 2023
@zannager zannager added the component: data grid This is the name of the generic UI component, not the React module! label May 30, 2023
@MBilalShafi
Copy link
Member

You can customize the filter operators to change the InputComponent to your custom one, inside the component, you can set the filter stroke time as you want.
The easiest way is to reuse the code of GridFilterInputValue component and use it as a custom InputComponent.

Here's a demo where stroke time is being used: https://mui.com/x/react-data-grid/filtering/#multiple-values-operator.

Alternatively, please allow users to be able to apply filters manually - via some kind of Apply filters button.

Can you explain more why you need this, the filters are applied automatically after the stroke time has passed, you can customize the InputComponent of the filter operator to do this immediately by calling applyValue function passed in props.

@MBilalShafi MBilalShafi added status: waiting for author Issue with insufficient information and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels May 30, 2023
@managervcf
Copy link
Author

managervcf commented May 31, 2023

You can customize the filter operators to change the InputComponent to your custom one, inside the component, you can set the filter stroke time as you want.
The easiest way is to reuse the code of GridFilterInputValue component and use it as a custom InputComponent.

Here's a demo where stroke time is being used: https://mui.com/x/react-data-grid/filtering/#multiple-values-operator.

Of course creating a custom InputComponent is something that I would have to do in the end if the SUBMIT_FILTER_STROKE_TIME remains unaccessible.

However, I feel that enabling this as a prop would be a better solution - like the debounceMs prop inside the GridToolbarQuickFilter.

Can you explain more why you need this, the filters are applied automatically after the stroke time has passed, you can customize the InputComponent of the filter operator to do this immediately by calling applyValue function passed in props.

As I'm using the server-side filtering, this kind of Apply filters button would let me reduce the number of back-end requests as filters would be applied on demand and not after each stroke. When dealing with a large data set, new request after each stroke can be quite expensive.

@github-actions github-actions bot removed the status: waiting for author Issue with insufficient information label May 31, 2023
@romgrk
Copy link
Contributor

romgrk commented Jun 6, 2023

I think we should expose it.

@MBilalShafi do you have any suggestion under which name we could expose it? Should it go on the root props or elsewhere?

@MBilalShafi
Copy link
Member

MBilalShafi commented Jun 15, 2023

@romgrk Yeah, it'll be less painful if it's readily customizable without customizing filter operators.

Probably, slotProps.filterPanel.filterDebounceMs could be a better option, then, although this is a non-conventional way but we will have to do something like this in the respective components (e.g. GridFilterInputValue):

const debounceMs = rootProps.slotProps.filterPanel.filterDebounceMs ?? DEFAULT_FILTER_STROKE_TIME

And we'll also have to exclude this prop somehow when we pass down the ...slotProps.filterPanel to the GridFilterPanel component.

return <FilterPanel {...props.slotProps?.filterPanel} />;

What do you think?

@romgrk
Copy link
Contributor

romgrk commented Jun 15, 2023

Is that setting only related to the filter panel? Could we make it a prop of the filter panel so we don't have to worry about excluding?

@MBilalShafi
Copy link
Member

MBilalShafi commented Jun 20, 2023

Yeah, we can make it a part of filterFormProps but the problem with that is if we pass it generically in currentOperator.InputComponent as a prop, it may cause React does not recognize the x prop on a DOM element error for the InputComponents that do not use it. e.g GridFilterInputBoolean or GridFilterInputSingleSelect as they destructure { ...others } to the underlying components.

<currentOperator.InputComponent
apiRef={apiRef}
item={item}
applyValue={applyFilterChanges}
focusElementRef={valueRef}
{...currentOperator.InputComponentProps}
{...InputComponentProps}
/>

So, the possible options seem to be, either we stop destructuring the others object in the internal components and make it a part of filterFormProps or use something like slotProps.filterPanel.filterDebounceMs as I suggested in the comment above.

@romgrk
Copy link
Contributor

romgrk commented Jun 20, 2023

Sounds good, let's go with slotProps.filterPanel.filterDebounceMs then.

@github-project-automation github-project-automation bot moved this to 🆕 Needs refinement in MUI X Data Grid Jun 20, 2023
@oliviertassinari oliviertassinari added the feature: Filtering Related to the data grid Filtering feature label Jul 12, 2023
@MBilalShafi MBilalShafi moved this from 🆕 Needs refinement to ✅ Done in MUI X Data Grid Aug 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: data grid This is the name of the generic UI component, not the React module! feature: Filtering Related to the data grid Filtering feature
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

5 participants