Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MUI DataGrid dynamic width according to longest data for column

I am using DataGrid from MUI and inside GridColDef I dont use anything related to width, I want to have columns to have width of longest data so that every letter is shown, is it possible?

Below is my GridColDef:

{
field: 'lastLogin',
type: 'dateTime',
headerName: 'Last login',
align: 'right',
headerAlign: 'right',
}
like image 779
Berk Can Avatar asked Jan 18 '26 19:01

Berk Can


2 Answers

I believe you can use minWidth, see here - material-ui / data-grid flexible column width min-width

It has been a while since I have used any of that myself but I do remember having a minWidth with elipsis.

like image 61
Zack Amin Avatar answered Jan 21 '26 09:01

Zack Amin


(Pro plan only)

Autosizing Reference: https://mui.com/x/react-data-grid/column-dimensions/#autosizing

<DataGrid
  {...otherProps}
  autosizeOptions={{
    columns: ['name', 'status', 'createdBy'],
    includeOutliers: true,
    includeHeaders: false,
  }}
/>
like image 39
Archit Garg Avatar answered Jan 21 '26 09:01

Archit Garg