[英]How can I change the width of a table cell of Material UI with React?
I have the following problem, I try to increase the table cell width, but I have no idea how to do it.我有以下问题,我尝试增加表格单元格的宽度,但我不知道该怎么做。 I work with Typescript.
我与 Typescript 合作。 I can only select the size for the TableCellProps and I can only set medium or small.
我只能 select TableCellProps 的大小,我只能设置中或小。 Does anyone have a solution?
有没有人有办法解决吗? I want to enlarge the blue colored table cell.
我想放大蓝色表格单元格。 1
1
<TableRow>
<TableCell align="left">address</TableCell> //sample Code, how i can set here the width
</TableRow>
As a second question, how can you limit the height of the whole table, so that you have to scroll horizontally and vertically in the table?作为第二个问题,你怎么能限制整个表格的高度,以至于你必须在表格中水平和垂直滚动?
You can simply add the width to the cell like this:您可以像这样简单地将宽度添加到单元格:
<TableCell width={300}>Dessert (100g serving)</TableCell>
This will make this cell 300 px wide.这将使该单元格宽 300 像素。
If you have not the material-ui installed, then you need to install it first as follows:如果您还没有安装 material-ui,则需要先安装如下:
// with npm
npm install @material-ui/core
// with yarn
yarn add @material-ui/core
then import it to the top of your file as follow:然后将其导入文件顶部,如下所示:
import {
createStyles,
Grid,
makeStyles,
Table,
TableBody,
TableCell,
TableContainer,
TableHead,
TableRow,
Theme,
withStyles,
} from '@material-ui/core';
create a function like this and set the width value as you wish:像这样创建一个 function 并根据需要设置宽度值:
const StyledTableCell = withStyles((theme: Theme) =>
createStyles({
head: {
backgroundColor: theme.palette.common.black,
color: theme.palette.common.white,
width: '50%',
fontSize: 20
},
}),
)(TableCell);
now look at the following example to see how you can use StyledTableCell
in your code:现在查看以下示例,了解如何在代码中使用
StyledTableCell
:
<Table
aria-label="collapsible table"
aria-labelledby="tableTitle"
>
<TableHead>
<TableRow>
<TableCell />
<TableCell>Document Title</TableCell>
<StyledTableCell align="right">Document Content</StyledTableCell>
</TableRow>
</TableHead>
<TableBody>
{rows.map((row) => (
<Row key={row.documentId} row={row} />
))}
</TableBody>
</Table>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.