简体   繁体   English

将样式应用到 antd 表列

[英]applying styles to antd table column

I have below table column configuration where i am rendering notes with custom function我有下表列配置,我在其中使用自定义函数渲染注释

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
  }
}]

And the below is the SectionNotes method下面是 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 */
};

here what i am doing is i will be looping through the notes and applying styles style={{ maxHeight: 300, overflowY: 'auto'}} to each note if it has minimum width then scrollbar applies.在这里我正在做的是我将循环浏览笔记并将样式style={{ maxHeight: 300, overflowY: 'auto'}}应用于每个笔记,如果它具有最小宽度,则滚动条应用。

and it is appearing like as in below image它看起来像下图在此处输入图片说明

But i would like to apply same styles for entire cell data and not on each note inside cell.但我想对整个单元格数据应用相同的样式,而不是在单元格内的每个音符上。

Could any one please let me know how can i achieve this?任何人都可以让我知道我怎样才能做到这一点? applying styles for entire cell or entire column as well.也为整个单元格或整个列应用样式。

I am using Ant Design table to render the data.我正在使用Ant Design表来呈现数据。

I have fixed with the below code我已经用下面的代码修复了

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>;
};

and then I am using like this as below然后我使用如下

fieldDefs: (results, isJsonData) => [
{
  title: 'Notes',
  name: 'notesHTML',
  table: {
    render: renderSectionNotes,
    searchable: true,
    width: 200
  }
}]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM