REECT MUI DATAGRID-插入线路断开时,当行中的文本命中最大宽度
我有一个使用MUI DataGrid创建的表,并且正在存储一些用户输入。 我的问题是,如果文本输入太大,则文本将在最后显示“ ...”。 我要实现的目标是如果文本太大,则是在该列内的线路,这就是一个示例。
我希望文本击中列的末尾,将文本分成更多行。
这是我的代码:
const columnData: GridColDef[] = [
{
field: "createdAt",
headerName: "DATE",
minWidth: 150,
width: 244,
valueFormatter: (params: GridValueFormatterParams) =>
dateString(DateTime.fromSeconds(params.value as number).toJSDate()),
},
{
field: "content",
headerName: "NOTE",
minWidth: 600,
width: 1150,
},
{
field: "note-menu-button",
disableColumnMenu: true,
sortable: false,
headerName: "",
width: 0,
renderCell: (params) => {
return (
<ActionMenu
id="note-menu-button"
menuItems={menu}
rowId={params.id}
/>
);
},
},
];
return (
<Table
{...props}
columns={columnData}
rowHeight={55}
autoHeight
pageSize={6}
/>
);
};
这是我加载表的地方:
<Card id="notes-table" sx={{ mb: 4 }}>
<CardContent>
<NotesTable
onNotesEditClick={(id: string) => {
openEditNoteDialog(id);
}}
onNotesDeleteClick={(id: string) => {
onDeleteNote(id);
}}
rows={notes}
loading={loading}
/>
</CardContent>
</Card>
I have a table that I created using MUI DataGrid, and I am storing some user input.
My issue is, if the text input is too big, the text will truncate showing "..." at the end.
What I'm trying to achieve is to break the line inside that column if the text is too big, here is the example.
I want the text to be broken into more lines if it hits the end of the column.
Here is my code:
const columnData: GridColDef[] = [
{
field: "createdAt",
headerName: "DATE",
minWidth: 150,
width: 244,
valueFormatter: (params: GridValueFormatterParams) =>
dateString(DateTime.fromSeconds(params.value as number).toJSDate()),
},
{
field: "content",
headerName: "NOTE",
minWidth: 600,
width: 1150,
},
{
field: "note-menu-button",
disableColumnMenu: true,
sortable: false,
headerName: "",
width: 0,
renderCell: (params) => {
return (
<ActionMenu
id="note-menu-button"
menuItems={menu}
rowId={params.id}
/>
);
},
},
];
return (
<Table
{...props}
columns={columnData}
rowHeight={55}
autoHeight
pageSize={6}
/>
);
};
Here is where I load the table:
<Card id="notes-table" sx={{ mb: 4 }}>
<CardContent>
<NotesTable
onNotesEditClick={(id: string) => {
openEditNoteDialog(id);
}}
onNotesDeleteClick={(id: string) => {
onDeleteNote(id);
}}
rows={notes}
loading={loading}
/>
</CardContent>
</Card>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
请尝试以下代码。
添加RenderCell如下所示。
Please try below code.
Add rendercell as shown below.
在Note列中使用渲染单元格方法并写入功能组件,并写出您的逻辑,如果超过某个长度走下一行,只需将数据传递到该函数组件
use render cell method in note column and write function component and write your logic if more than some length go next line then just pass your data to that function component
使用此ValueGetter,您可以调整行的长度,值长度。
Using this valueGetter you can adjust the length of the row , value length.
使用getrowheight将修复它:
use getRowHeight will fix it: