【问题标题】:How to push dynamic columns and row data to antd table如何将动态列和行数据推送到antd表
【发布时间】:2021-08-02 16:51:21
【问题描述】:

以下代码不接受行列数组

这里是 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
  });
}
}

【问题讨论】:

  • 您不能像这样推送对象属性。删除带有 j 的 for 循环:data.datacloumn[i] = [...rowdata[i]]
  • 非常感谢您的回复.. 当删除循环并添加这一行 data.push(datacolumn[i]=[...rowdata[i]] 但 rowdata 仍然没有逐行显示.. const data = []; for (var i = 0; i
  • GroupId ,名称, 缩写, Partners 1 1 1 1 ABC ABC ABC ABC A A A A AAA AAA AAA AAA 重复行
  • GroupId ,Name, abbrevation, Partners .. are my columns expected output 1 ABC A AAA
  • 为什么不用useState钩子更新表呢?

标签: javascript reactjs antd


【解决方案1】:

感谢您的建议 这里的解决方案:已将我的结果更改为 title 和 dataIIndex 格式,所以我意识到 antd 表只接受 title 和 dataIIndex 格式

让 datacloumns = reportDataRows && Object.keys(reportDataRows[0])?.map((key) => ( {cloumns.push({ 标题:键,数据索引:键, //defaultSortOrder: 'descend', 分拣机:真 })} ))

< 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 }} 数据源 = { reportDataRows === 未定义? [] : 报告数据行} />

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-03-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-01-23
    相关资源
    最近更新 更多