material-react-table icon indicating copy to clipboard operation
material-react-table copied to clipboard

[Styles]: column widths

Open nichita-pasecinic opened this issue 3 years ago • 6 comments

material-react-table version

1.10.0

react & react-dom versions

17.0.2

Describe the bug and the steps to reproduce it

The table I'm building needs to have the first column with a maxWidth (maxSize) configured to a value, and the rest columns needs to adjust dynamically (by their content). Also the table should be compact & not resizable (from the user side)

Currently the auto width on columns is working as expected, but how to set a maxSize on a column that will work ?

Applying tableLayout to fixed would not be a solution as the table columns will not expand to their widths

Minimal, Reproducible Example - (Optional, but Recommended)

https://stackblitz.com/edit/github-ucbgy6?file=src%2FTS.tsx,src%2FmakeData.ts

{
        accessorKey: 'firstName',
        header: 'First Name',
        size: 100,
        maxSize: 200,
      },

Screenshots or Videos (Optional)

image

Do you intend to try to help solve this bug with your own PR?

No, because I do not know how

Terms

  • [X] I understand that if my bug cannot be reliably reproduced in a debuggable environment, it will probably not be fixed and this issue may even be closed.

nichita-pasecinic avatar Apr 18 '23 10:04 nichita-pasecinic

Try add props enableColumnResizing to the <MaterialReactTable /> component. It should turn the value inside cell to end with ellipsis.

You can refer to this documentation. https://www.material-react-table.com/docs/guides/column-resizing#column-resize-mode

domi-glyph avatar Apr 19 '23 01:04 domi-glyph

@domi-glyph I don't want the columns to be resizable from user perspective.

Thanks.

nichita-pasecinic avatar Apr 19 '23 05:04 nichita-pasecinic

+1 for anything we can do to make automatic column sizing more flexible. I've struggled with this in the past with other grids. Different layouts that I've found useful in the past, but that are hard or impossible to create, include:

  1. Size each column based on its content. (Tricky, obviously, with paging or virtual scrolling as we would prefer the widths don't jump around much.)
  2. Size each column identically as an equal percentage of screen width.
  3. Size most columns to their content, but make one column (the first or last, generally) expand to fill all available space.
  4. Set all columns to a specified fixed size.
  5. Set a fixed width on the first column (generally a long-ish name of something), size the middle columns according to their content, and make the rightmost column fill all available space.

Anyway I don't know how all that should work, or what works already here -- just some thoughts on what would be handy.

githorse avatar May 10 '23 14:05 githorse

Did anyone found any solution for this, facing similar issue. Thanks

pratikdas44 avatar Aug 30 '23 14:08 pratikdas44

Any update? I don't want to enableColumnResizing to fix column width

wfsm avatar Dec 22 '23 07:12 wfsm

In v2, layoutMode: 'grid-no-grow' gives columns an absolute width and they will not grow.

layoutMode: 'grid' will grow all columns to fill the remaining space in the table equally.

layoutMode: 'semantic' (default unless column resizing or virtualization are enabled) is the only layout mode that will attempt to "autofit" by content. (Using the default CSS features)

Now in v2.8.0, this is getting better for the grid and grid-no-grow layout modes. There is a new grow column option that takes a boolean or a number that determines flex grow and shrink values.

So you will be able to control growing/shrinking on a per column basis in the grid/grid-no-grow layout modes now.

To learn more: I updated all of these storybook examples: https://www.material-react-table.dev/?path=/story/styling-custom-column-widths--custom-widths-semantic

And added a new section to the column sizing docs: https://www.material-react-table.com/docs/guides/column-resizing#column-grow

KevinVandy avatar Jan 20 '24 03:01 KevinVandy