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

Changing style (column width, cell width, etc.)

Open wangb-ctrl opened this issue 7 years ago • 53 comments

  • [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: screen shot 2019-03-07 at 1 33 47 pm

  • [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? screen shot 2019-03-07 at 1 45 35 pm

  • [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!

wangb-ctrl avatar Mar 07 '19 21:03 wangb-ctrl

Hi @brittanywang ,

I will check this case asap.

mbrn avatar Mar 08 '19 12:03 mbrn

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.

timrchavez avatar Mar 14 '19 14:03 timrchavez

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

orestesparra avatar Mar 20 '19 16:03 orestesparra

i face the same issue. setting width in headerStyle doesnt work for me. but cellStyle does.

ShawTim avatar Mar 21 '19 11:03 ShawTim

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.

mbrn avatar Mar 21 '19 11:03 mbrn

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

orestesparra avatar Mar 21 '19 14:03 orestesparra

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

wangb-ctrl avatar Mar 22 '19 04:03 wangb-ctrl

@brittanywang

You can change fonts with css too,

mbrn avatar Mar 22 '19 05:03 mbrn

i face the same issue, one of my data is so long but can set cellstyle:{whiteSpace:'nowrap'} and it works for me

symnetry avatar Mar 27 '19 10:03 symnetry

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.

hasankhalid avatar Mar 28 '19 08:03 hasankhalid

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?

ambr89 avatar Apr 16 '19 08:04 ambr89

Material-ui table components uses auto layout. So columns are being auto width. Currently i cant change them.

mbrn avatar Apr 16 '19 18:04 mbrn

Thanks!

ambr89 avatar Apr 17 '19 07:04 ambr89

@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!

vladimanaev avatar Jun 14 '19 16:06 vladimanaev

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; }

FoxTM4 avatar Jul 30 '19 14:07 FoxTM4

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.

conerye avatar Oct 29 '19 17:10 conerye

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?

bableves avatar Nov 19 '19 10:11 bableves

@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 avatar Nov 22 '19 14:11 dalisalvador

@dalisalvador your solutions works perfect, thanks

midoalone avatar Jan 11 '20 09:01 midoalone

How to make fixed( sticky header) in Material-table

vnanaware avatar Jan 20 '20 13:01 vnanaware