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] The popover for the GridToolbarFilterButton and GridToolbarColumnsButton should open under their respective button #13202

Closed
mahammahmood opened this issue May 22, 2024 · 4 comments
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 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

@mahammahmood
Copy link

mahammahmood commented May 22, 2024

Screenshot 2024-05-22 110504

The problem in depth

When i implement the solution you guys provided i got error on this Error: Maximum update depth exceeded. This can happen when a component repeatedly calls setState inside componentWillUpdate or componentDidUpdate. React limits the number of nested updates to prevent infinite loops.

this is my code. can you please help me to resolve this issue.

interface CustomToolbarProps {
  loadingState?: boolean;
  showCustomMenuButton?: boolean;
  RowSelectionModel?: boolean;
  setFilterButtonEl?: React.Dispatch<React.SetStateAction<HTMLButtonElement | null>>;
}

export const CustomToolbar: React.FC<CustomToolbarProps> = ({
     loadingState = true,
    showCustomMenuButton = false,
    RowSelectionModel = false,
    setFilterButtonEl,
})=> {
return (
<GridToolbarContainer>
    <GridToolbarColumnsButton />
     <GridToolbarFilterButton 
           ref={setFilterButtonEl} />
 </GridToolbarContainer>
  );
}
const Page = () => {
 const [filterButtonEl, setFilterButtonEl] = React.useState<HTMLButtonElement | null>(null);
  <DataGrid
            rows={locationRowsV2}
            columns={columns}
             slots={{
              toolbar: () => (
                <CustomToolbar
                   setFilterButtonEl={setFilterButtonEl}
                   filterButtonEl={filterButtonEl}
                  loadingState={loading}
                  RowSelectionModel={rowSelectionModel}
                  showCustomMenuButton={true}
             }}
           slotProps={{
              panel: {
                anchorEl: filterButtonEl,
              },
              columnsPanel: {
                sx: {
                  [`& .MuiDataGrid-columnsManagement > label:first-child, & .MuiDataGrid-columnsManagement > label:last-child`]:
                    {
                      display: '',
                    },
                },
              },
            }}
}

Your environment

`npx @mui/envinfo`
  Don't forget to mention which browser you used.
  Output from `npx @mui/envinfo` goes here.

Search keywords: Data ,Grid , Pro, GridToolbarFilterButton, GridToolbarColumnsButton, version 7
Order ID: 81584

@mahammahmood mahammahmood added status: waiting for maintainer These issues haven't been looked at yet by a maintainer support: commercial Support request from paid users labels May 22, 2024
@michelengelen michelengelen added 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 support: pro standard Support request from a Pro standard plan user. https://mui.com/legal/technical-support-sla/ labels May 22, 2024
@michelengelen michelengelen changed the title The popover for the GridToolbarFilterButton and GridToolbarColumnsButton should open under their respective button [data grid] The popover for the GridToolbarFilterButton and GridToolbarColumnsButton should open under their respective button May 22, 2024
@michelengelen
Copy link
Member

michelengelen commented May 22, 2024

Please follow the code example as precisely as possible.
What you did is passing in a function literal as component for the toolbar slot.
This should be memoized, otherwise it will infinitely rerender.
You can then pass the custom slots via the slotProps prop on the data grid.

The example you gave is incorrect jsx syntax as well and not working at all.

This is the code example you gave in a fixed version:

import * as React from 'react';
import {
  DataGrid,
  GridToolbarColumnsButton,
  GridToolbarContainer,
  GridToolbarFilterButton,
  GridToolbarProps
} from "@mui/x-data-grid";
interface CustomToolbarProps extends GridToolbarProps {
  loadingState?: boolean;
  showCustomMenuButton?: boolean;
  rowSelectionModel?: boolean;
  setFilterButtonEl?: React.Dispatch<React.SetStateAction<HTMLButtonElement | null>>;
}

function CustomToolbar ({
  showCustomMenuButton = false,
  setFilterButtonEl,
}: CustomToolbarProps) {
  return (
    <GridToolbarContainer>
      <GridToolbarColumnsButton />
      <GridToolbarFilterButton
        ref={setFilterButtonEl} />
    </GridToolbarContainer>
  );
}

export default function() {
  const [filterButtonEl, setFilterButtonEl] = React.useState<HTMLButtonElement | null>(null);
  return (
    <DataGrid
      rows={[]}
      columns={[]}
      slots={{
        toolbar: CustomToolbar
      }}
      slotProps={{
        panel: {
          anchorEl: filterButtonEl,
        },
        toolbar: {
          setFilterButtonEl,
          showCustomMenuButton: true,
          rowSelectionModel: false,
          loadingState: false,
        },
        columnsPanel: {
          sx: {
            [`& .MuiDataGrid-columnsManagement > label:first-child, & .MuiDataGrid-columnsManagement > label:last-child`]:
              {
                display: '',
              },
          },
        },
      }}
    />
  )
}

It is important that the component passed into the slot is either memoized or a static component, not a function literal.

As a tip for the next time: Providing a live code example really helps in fixing the problem.

@michelengelen michelengelen 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 22, 2024
@michelengelen
Copy link
Member

Reference to the other issue #13186

@michelengelen
Copy link
Member

When the provided solution works please feel free to close the issue @mahammahmood
Thanks! 🙇🏼

Copy link

⚠️ 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.

@mahammahmood: 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.

@github-actions github-actions bot removed the status: waiting for author Issue with insufficient information label May 27, 2024
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 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