Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Customize MUI Gridtoolbar

I'm using MUI Datagrid and i wanna know if there is a way to customize the gridtoolbar with custom buttons and text.

Thanks.

Federico

This is the toolbar i wanna customize

like image 330
fBare Avatar asked Mar 07 '26 10:03

fBare


2 Answers

I imagine that you know, thak to enable the toolbar you need to add the Toolbar: GridToolbar to the grid components prop - like

<DataGrid
  {...data}
  components={{
    Toolbar: GridToolbar,
  }}
/>

So, if you want to custom, and add others things, you must compose your own toolbar, for example:

function CustomToolbar() {
  return (
    <GridToolbarContainer>
      <GridToolbarColumnsButton />
      <GridToolbarFilterButton />
      <GridToolbarDensitySelector />
      <GridToolbarExport />
    </GridToolbarContainer>
  );
}

And do the same thing:

<DataGrid
  {...data}
  components={{
    Toolbar: CustomToolbar,
  }}
/>

Source: https://mui.com/x/react-data-grid/components/#toolbar

like image 192
Daniel Bueno Avatar answered Mar 08 '26 22:03

Daniel Bueno


The components prop is depricated. Now, you can do:

<DataGrid
  {...data}
  slots={{
    toolbar: CustomToolbar,
  }}
/>
function CustomToolbar() {
  return (
    <GridToolbarContainer>
      <GridToolbarColumnsButton />
      <GridToolbarFilterButton />
      <GridToolbarDensitySelector />
      <GridToolbarExport />
    </GridToolbarContainer>
  );
}
like image 31
Luke Vanzweden Avatar answered Mar 08 '26 22:03

Luke Vanzweden