如何将动态列和行数据推送到antd表

Dee*_*ula 5 javascript reactjs antd

在此输入图像描述

下面的代码不接受行和列的数组

这是 antd 的例子:

const data = [];
for (let i = 0; i < 4; i++) {
  data.push({
    key: i,
    name: `Edward King ${i}`,
    age: 32
    //  address: `London, Park Lane no. ${i}`
  });
}

Tried same logic in below: 
// columns :datacloumns1
// rows :rowdata

const data = [];
for (let i = 0; i < 4; i++) {
   for (var j = 0; j < reportDataRows?.length; j++){
  data.push({
  datacloumns1[i]:rowdata[i] // here i am binding row to the exact column but this is not accepting
  });
}
}
Run Code Online (Sandbox Code Playgroud)

Dee*_*ula 1

谢谢你的建议。

这是解决方案:将我的结果更改为titledataIndex格式,所以我意识到 antd 表只接受 titledataIndex格式。

let datacloumns = reportDataRows && Object.keys(reportDataRows[0])?.map((key) => (
    <span >{cloumns.push({
        title: key, dataIndex: key,
        //defaultSortOrder: 'descend',
        sorter: true
    })}
    </span>))

< Table 
  rowClassName = {(record, index) => index % 2 === 0 ? 'table-row-light' : 'table-row-dark'} 
  size = { 'default'} 
  columns = { cloumns } 
  bordered = { true} 
  sortDirections = { ['ascend', 'descend'] } 
  loading = { reportDataRows === undefined ? true : false} 
  pagination = {{ pageSize: 10 }} dataSource = { reportDataRows === undefined ? [] : reportDataRows} 
/>
Run Code Online (Sandbox Code Playgroud)