Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Material UI v1 - set table column widths

Tags:

I want to set column widths on a Material UI table using css (not inside react using "classes"). But I don't understand how the column widths are controlled. I try to set widths on the TH columns but it doesn't work.

See example: Material ui table example (See style.css)

I don't understand how the table column widths are controlled on the "Simple Table" on the Mui table: Simple table (you can see that the first column is wider than the others. How?)

So how does it work, and how can I modify the settings?

like image 329
Galivan Avatar asked Jul 06 '18 18:07

Galivan


People also ask

How to change width of column in Material UI table?

To give width to each column, colspan is better solution than fixing the width, it will make table responsive depending on screen/grid size. So you can put colSpan={4} for example on column components. And to fix column width within the colspan table-layout: fixed style will help.

How to set width in MUI table?

As shown in the previous section, simply use the style or classes prop on the TableCell to set the width, i.e. style={{ width: "25%" }} .


1 Answers

Try using colgroup, worked for me in Material-UI V1

<Table>    <colgroup>       <col style={{width:'10%'}}/>       <col style={{width:'20%'}}/>       <col style={{width:'70%'}}/>    </colgroup>    <TableHead>       <TableRow>          <TableCell>Head1</TableCell>          <TableCell>Head2</TableCell>          <TableCell>Head3</TableCell>       </TableRow>    </TableHead>    <TableBody>       <TableRow>          <TableCell>Data1</TableCell>          <TableCell>Data2</TableCell>          <TableCell>Data3</TableCell>       </TableRow>    </TableBody> </Table> 
like image 51
Pirate4 Avatar answered Oct 06 '22 00:10

Pirate4