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] GridToolbarQuickFilter loses focus when setting state variable #16061

Closed
entaildevops opened this issue Jan 2, 2025 · 5 comments
Closed
Labels
component: data grid This is the name of the generic UI component, not the React module! customization: logic Logic customizability support: commercial Support request from paid users support: pro standard Support request from a Pro standard plan user. https://mui.com/legal/technical-support-sla/

Comments

@entaildevops
Copy link

entaildevops commented Jan 2, 2025

The problem in depth

I am keeping track of selected row. It works, but when a row is selected and GridToolbarQuickFilter is used, it loses focus when the currently selected row is filtered out. This leads to bad UX. How could I prevent this from happening?

Codesandbox here.

First select a row and then type something in the quick filter box to reproduce the issue.

Your environment

`npx @mui/envinfo`
System:
OS: Windows 11 10.0.26100

Binaries:
Node: 18.16.0 - C:\Program Files\nodejs\node.EXE
npm: 9.5.1 - C:\Program Files\nodejs\npm.CMD
pnpm: Not Found
Browsers:
Chrome: Not Found
Edge: Chromium (131.0.2903.99)

 Used latest Edge 

Search keywords: DataGrid GridToolbarQuickFilter

Order ID: 98745

@entaildevops entaildevops added status: waiting for maintainer These issues haven't been looked at yet by a maintainer support: commercial Support request from paid users labels Jan 2, 2025
@github-actions github-actions bot added component: data grid This is the name of the generic UI component, not the React module! support: pro standard Support request from a Pro standard plan user. https://mui.com/legal/technical-support-sla/ labels Jan 2, 2025
@entaildevops
Copy link
Author

I Just made the codesanbox public, was private by accident =)

@michelengelen
Copy link
Member

michelengelen commented Jan 6, 2025

The reason is that you need to define the CustomToolbar outside of the main component, since a rerender will also affect the custom component and therefor losing focus.

if you need the rows you can get it from the apiRef ... for components that get rendered inside the grid context and need to access it you can use useGridApiContext:

const CustomToolbar = () => {
  const apiRef = useGridApiContext();
  const rowsCount = apiRef.current?.state?.rows.totalRowCount;
  console.log('rowsCount', rowsCount);
  return (
    <GridToolbarContainer>{rowsCount ? <GridToolbarQuickFilter /> : null}</GridToolbarContainer>
  );
};

@michelengelen michelengelen added status: waiting for author Issue with insufficient information customization: logic Logic customizability and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Jan 6, 2025
@michelengelen michelengelen changed the title GridToolbarQuickFilter loses focus when setting state variable [data grid] GridToolbarQuickFilter loses focus when setting state variable Jan 6, 2025
@entaildevops
Copy link
Author

This solved my issue, thanks!

@github-actions github-actions bot added status: waiting for maintainer These issues haven't been looked at yet by a maintainer and removed status: waiting for author Issue with insufficient information labels Jan 7, 2025
@entaildevops
Copy link
Author

I guess im allowed to close the issue

@github-actions github-actions bot removed the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Jan 7, 2025
Copy link

github-actions bot commented Jan 7, 2025

This issue has been closed. If you have a similar problem but not exactly the same, please open a new issue.
Now, if you have additional information related to this issue or things that could help future readers, feel free to leave a comment.

Note

@entaildevops How did we do? Your experience with our support team matters to us. If you have a moment, please share your thoughts in this short Support Satisfaction survey.

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! customization: logic Logic customizability support: commercial Support request from paid users support: pro standard Support request from a Pro standard plan user. https://mui.com/legal/technical-support-sla/
Projects
None yet
Development

No branches or pull requests

2 participants