reactjs - Material-UI DataGrid 基于文本内容的动态行高
问题描述
使用 DataGrid 时,我无法弄清楚如何使行高可变,以便行高动态基于单元格中文本内容的长度。
我在想我需要renderCell
在具有较长文本的列上添加,并使用该<Typography>
组件,但我不知道用什么参数来设置它的样式。
有很多关于如何处理截断、省略号等的文档,但我似乎无法弄清楚我需要根据内容申请可变行高的内容。
解决方案
const StyledDataGrid = withStyles({
root: {
'& .MuiDataGrid-renderingZone': {
maxHeight: 'none !important',
},
'& .MuiDataGrid-cell': {
lineHeight: 'unset !important',
maxHeight: 'none !important',
whiteSpace: 'normal',
},
'& .MuiDataGrid-row': {
maxHeight: 'none !important',
},
},
})(DataGrid);
有关示例,请参阅此演示。
推荐阅读
- azure - 从 Azure Active Directory 创建的租户是否完全独立?
- grep - 具有至少一个匹配值和至少一个不匹配的 Grep
- iframe - Headless Moodle:Iframe 身份验证
- python - 从python中的字典列表中获取最大值字典
- python - xlsxwriter:根据数据框排序值创建多个工作表
- javascript - 我如何遍历具有相同列表的列表
- stm32 - HAL_SPI_Transmit 比直接寄存器操作更快,为什么?
- python - 如何从熊猫数据框中的团队名称中提取带有reg的城市名称
- python - 在 virtualenv (Linux) 中选择了错误版本的 Python
- google-chrome - 如何使用量角器在 chrome 中设置具有纬度经度位置输入的传感器?