[英]applying styles to antd table column
我有下表列配置,我在其中使用自定义函数渲染注释
fieldDefs: (results, isJsonData) => [
{
title: 'Notes',
name: 'notesHTML',
table: {
render: SectionNotes,
searchable: true,
width: 200,
style: { maxHeight: 300, overflowY: 'auto'} // tried with this but not working this way
}
}]
下面是 SectionNotes 方法
const SectionNotes = notes => {
if (!notes) return '';
/* eslint-disable react/no-danger */
return notes.map((note, index) => (
<div key={note} style={{ maxHeight: 300, overflowY: 'auto'}}>
<span style={{ fontWeight: 'bold' }}>
{index + 1}.{' '}
</span>
<span dangerouslySetInnerHTML={{ __html: sanitizer(note) }} />
</div>
));
/* eslint-enable react/no-danger */
};
在这里我正在做的是我将循环浏览笔记并将样式style={{ maxHeight: 300, overflowY: 'auto'}}
应用于每个笔记,如果它具有最小宽度,则滚动条应用。
但我想对整个单元格数据应用相同的样式,而不是在单元格内的每个音符上。
任何人都可以让我知道我怎样才能做到这一点? 也为整个单元格或整个列应用样式。
我正在使用Ant Design
表来呈现数据。
我已经用下面的代码修复了
export const SectionNotes = notes => {
if (!notes) return '';
/* eslint-disable react/no-danger */
return notes.map((note, index) => (
<div key={note}>
<span style={{ fontWeight: 'bold' }}>
{index + 1}.{' '}
</span>
<span dangerouslySetInnerHTML={{ __html: sanitizer(note) }} />
</div>
));
/* eslint-enable react/no-danger */
};
export const renderSectionNotes = text => {
return <div style={{ maxHeight: 250, overflowY: 'auto' }}>{SectionNotes(text)}</div>;
};
然后我使用如下
fieldDefs: (results, isJsonData) => [
{
title: 'Notes',
name: 'notesHTML',
table: {
render: renderSectionNotes,
searchable: true,
width: 200
}
}]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.