Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vertical Table in Material-UI

By vertical table, I mean the first column of each row is a header. Like this:

<table>
    <tr>
        <th>Header 1</th>
        <td>Cell 1</td>
    </tr>
    <tr>
        <th>Header 2</th>
        <td>Cell 2</td>
    </tr>
</table>

The problem is, to render the <TableCell /> to be a <th /> we need to wrap it inside <TableHead />, otherwise it will render to <td />. But <TableHead /> also cannot be placed inside <TableRow /> since it renders to <thead />. So the following code won't work:

<Table>
    <TableRow>
        <TableHead>
            <TableCell>Header 1</TableCell>
        </TableHead>
        <TableCell>Cell 1</TableCell>
    </TableRow>
    <TableRow>
        <TableHead>
            <TableCell>Header 1</TableCell>
        </TableHead>
        <TableCell>Cell 2</TableCell>
    </TableRow>
</Table>

Then, how can I achieve the first example using Material-UI?

like image 439
SnekNOTSnake Avatar asked Feb 01 '26 21:02

SnekNOTSnake


1 Answers

Ohh, Nevermind.

I am not keen enough to see the variant property in the documentation. All you need to do is set the variant property of <TableCell /> to head.

<Table>
    <TableRow>
        <TableCell variant="head">Header 1</TableCell>
        <TableCell>Cell 1</TableCell>
    </TableRow>
    <TableRow>
        <TableCell variant="head">Header 1</TableCell>
        <TableCell>Cell 2</TableCell>
    </TableRow>
</Table>
like image 162
SnekNOTSnake Avatar answered Feb 04 '26 14:02

SnekNOTSnake