简体   繁体   English

如何在 Antd Table 中将多个数据显示到单个列中?

[英]How to display Multiple data into a single column in Antd Table?

So I want to show multiple data in a single cell of an ant design table.所以我想在 ant 设计表的单个单元格中显示多个数据。 Seems it allows only to insertion of a single data element.似乎它只允许插入单个数据元素。 Is that possible to combine multiple data into a single cell?是否可以将多个数据组合到一个单元格中?

here is what the data object looks like:这是数据 object 的样子:

data {
    transactionNo
    transactionTypeNo
    transactionType
    createdTstamp
    sourceNo
    accountNo
    currencyCd
    
  }

These are the table columns这些是表格列

const columns = [
{
  title: 'Transaction No',
  dataIndex: 'transactionNo',
  key: 'transactionNo',
  align: 'left',
  },
},
{
  title: 'Transaction Date',
  dataIndex: 'createdTstamp',
  defaultSortOrder: DESC,
  sortable: true,
  key: 'createdTstamp',
},
{
  title: 'Description',
  dataIndex: 'transactionType',
  key: 'transactionType',
  align: 'left',
  textWrap: 'wrap',
  defaultHidden: false,
  render: ( record) => (
    <>{record.transactionType}</>
  ),
},

I want to show both transactionType and sourceNo in a single cell.我想在单个单元格中同时显示transactionTypesourceNo Already tried using record but no luck.已经尝试使用记录但没有运气。 And I'm using react with typescript.我正在使用 typescript 做出反应。

You can use Render Method in the antd Columns.您可以在 antd Columns 中使用 Render Method。 You have found almost, just need to reference the record correctly..你已经发现差不多了,只需要正确引用记录..

{
  title: 'Description',
  dataIndex: 'transactionType',
  key: 'transactionType',
  align: 'left',
  textWrap: 'wrap',
  defaultHidden: false,
  // in Render first param returns current field, second params return entire data
  render: (text, record) => (
    <>{record.transactionType} {record.sourceNo}</>
  ),
},

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

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