Material-table: Column Width!

Created on 29 Aug 2019  Â·  13Comments  Â·  Source: mbrn/material-table

How do you set the width for a column? Am I missing something? How are people adjusting column sizes?

It would be great if it was a simple as =>
var columns = [ { title: 'FirstName', field: 'firstName', width: 100 }, { title: 'LastName', field: 'lastName', width: 100 } ];

has a solution

Most helpful comment

You can set the minWidth of a column in cellStyle/headerStyle like so:
{ title: "First name", field: "firstName", headerStyle: {minWidth: 100}, cellStyle: {minWidth: 100} }

I've seen other people do the same using width in place of minWidth, but I just could not get that to work for some reason.

All 13 comments

You can set the minWidth of a column in cellStyle/headerStyle like so:
{ title: "First name", field: "firstName", headerStyle: {minWidth: 100}, cellStyle: {minWidth: 100} }

I've seen other people do the same using width in place of minWidth, but I just could not get that to work for some reason.

@mbrn hi, would you please consider this feature? A convenient way to control the width of column is common in use cases and other table libraries.

I have tried multiple approaches to put minWidth, maxWidth, width in 'px' and also tried to render custom HTML to override the width but no luck. Is there any solution to adjust the width of the columns. I have tried with setting the tableLayout to 'fixed' with other permutations too. Any suggestion would be helpful. Thanks in advance

Looks like certain properties are indeed overwritten on the spread of headerStyle

<TableCell padding="none" key="key-selection-column" className={this.props.classes.header} style={{ ...this.props.headerStyle, width: selectionWidth }} >

No matter what you pass as width, it will always be overwritten.

@mbrn this appears to be tied to work you did in a7ee2d4, would a PR that checks for the presence of a tableLayout: fixed, and then if one exists, checks for a headerStyle be welcome here?

@mbrn
Hi. Is this fixed?
tableLayout: "fixed" seems not working neither.

I have the same issue either. Tried tableLayout fixed, but it does not work

How do you set the width for a column? Am I missing something? How are people adjusting column sizes?

It would be great if it was a simple as =>
var columns = [ { title: 'FirstName', field: 'firstName', width: 100 }, { title: 'LastName', field: 'lastName', width: 100 } ];

This is already implemented: { title: 'First Name', field: 'first_name', width: 100 },

Ah thx. Works

@Domino987 width should be added to the documentation.

@michaelGregoire you are right. Can you open a PR to fix this?

Sure. This repo (https://github.com/mbrn/material-table.com), correct?

Yes that correct

Was this page helpful?
0 / 5 - 0 ratings