Changing style (column width, cell width, etc.)
- [x] Is there another way to change the column/cell styles? I tried what was suggested in issue (#261) as in:
columns=
{ title: 'Name', field: 'name',
cellStyle: {
width: 20,
maxWidth: 20
},
headerStyle: {
width:20,
maxWidth: 20
}
},
but there are no changes to the width of the columns. I also tried changing the width and maxWidth:1 to see if there were any changes and there weren't:

-
[x] After fixing the size of the column, is there a way to not make the top chart expanded with the Detail Panel is shown?

-
[x] Is there a way to change the font for the data displayed (for consistency with my headers) as well? I tried doing:
data={[
{ cField: 'Subject', result: this.state.subject, headerStyle: { fontSize: 20}},
{ cField: 'Location', result: this.state.location, headerStyle: { fontSize: 20}}
]}
This is a pretty heavy post. Thank you in advance!
Hi @brittanywang ,
I will check this case asap.
cellStyle works for me but headerStyle does not appear to be working. When I set width: '100%' in headerStyle, I expect it to apply width: 100% to the header for this column, but I do not believe that's happening.
Hi, Im not sure if was fixed this, but Im using Material-Table version 1.24
and it works for me. Maybe Im not understanding very well the doubt. (forgive me if that is the case)
Please try to change the style like this:
headerStyle: {width: '50%', backgroundColor: '#ddd', height: 10, textAlign:'center'}
I beleive that only works with inline style, using JS for the style,
I tried others way, and doesnt works, Im not sure way, I hope @mbrn can find the solutions.
I hope this comment help you
Best Regards
i face the same issue. setting width in headerStyle doesnt work for me. but cellStyle does.
Actually, material-ui table components do not let to change width of columns. It set all columns' width automatically. But i will try to broke it with css.
Hi, please check this in order to analyze why is working for me https://codesandbox.io/s/8y77w4yr40
Maybe you have to import this HOC from material-ui to your class and wrap the class name at the end with that, like this:
import { withStyles } from "@material-ui/core/styles"; import stylepage from "stylepage";
class App extende React.Component . . export default withI18next(["home", "common"])(withStyles(stylespage)(App ));
I hope this works now for you
But it will be nice it could be more easy to modify
Best Regards
I figured out how to address sub-issue 2...
- [x] (not having the top chart expanded with the Detail Panel is shown).
It is entirely dependent on the data generated. One of my data fields happens to be really, really long so the width is adjusted accordingly. To fix this, I adjusted the css overflow.
Hoping someone can find a way to
- [ ] change the font for the generated data
@brittanywang
You can change fonts with css too,
i face the same issue, one of my data is so long but can set cellstyle:{whiteSpace:'nowrap'} and it works for me
Is there anyway to perhaps change the padding properties in material ui's TableCell component? I want to decrease the width of the column which contains only a number but using cellStyle:{width: '75px'} won't work.
Hi @hasankhalid to change padding size, I've set
<MaterialTable
columns={[
{ title: 'Nome', field: 'name', cellStyle:{ padding: '5px'} }, // change cell padding
{ title: 'Valido ', field: 'isValid', cellStyle:{padding: '5px'} }
]}
data={ ... my data ...}
title="My Title"
options={{
toolbar: false,
paging: false,
headerStyle:{backgroundColor:'red', padding: '5px'}, //change header padding
//cellStyle:{ padding: '5px'} here not work for me
}}
/>
Anyway, I've the problem that I can't set exactly width.
Have you solve this problem?
Material-ui table components uses auto layout. So columns are being auto width. Currently i cant change them.
Thanks!
@mbrn, is there any plan on supporting column width adjustments?
When having table with many (10-15) columns and with text of a sentence the table becomes very ugly and not readable.
Thanks!
You can place something like this in your css file and it will make long rows not ugly. Probably will have to change numbers but this works for me. .MuiTableCell-alignLeft{ width: 10px; max-width: 32em; text-overflow: inherit; overflow: scroll; }
Is it possible to change the width of the column that contains the detail panel expansion icon? I would like to set it to a set width, which is much narrower than it defaults to.
Is it possible to change the width of the column that contains the detail panel expansion icon? I would like to set it to a set width, which is much narrower than it defaults to.
I need that too. Any update on this one?
@mbrn @symnetry @vladimanaev The best way I found to change the width of the columns and potentially style of the cells/cell is the following:
columns={[
...state.columns.map(data => {
return {
field: data.field,
title: data.title,
render: rowData =>
(<div style={{minWidth: data.field === "columnToChange" ? "250px" : null, paddingLeft: "10px"}}> {rowData[data.field]} </div>)
};
})
]}
Basically renders a div with the desired width, and autolayout will do the rest. Hope that makes sense.
@dalisalvador your solutions works perfect, thanks
How to make fixed( sticky header) in Material-table