【问题标题】:Dynamically add a new row to ag-grid with dynamic (variable) columns将新行动态添加到 ag-grid
【发布时间】:2021-11-15 13:24:52
【问题描述】:

我正在尝试在我的 ReactJS 页面的 ag-grid 上动态添加按钮单击事件的新行。

当我在设计时知道固定数量的列时,下面的代码对我有用..

let row ={
products1: "a",
products2: "b",
products3: "c"
}

gridApi.updateRowData(add: [row])

但如果列数是可变的并且仅在运行时已知,我也需要让它工作。 不确定这在 ReactJS/ag-grid 中是否可行?

我需要在这里使用数组的地图功能吗? 到目前为止,我已经尝试了以下方法,但给出了语法错误。

const rowArray = []

for(int index=0; index < myProductColumnsArrAtRunTime.length;index++)
{
    rowArray.map((myProductColumnsArrAtRunTime[i], myProductColumnsArrAtRunTime[i].category) => {myProductColumnsArrAtRunTime[i]}:  {myProductColumnsArrAtRunTime[i].category});                                                                                                     
}
gridApi.updateRowData(add: [rowArray])

【问题讨论】:

    标签: reactjs ag-grid


    【解决方案1】:

    如果在网格初始状态后列数发生变化,则需要先更新列定义。更新列定义参考documentation

    稍后,“添加行”按钮应根据新的列集添加新的 rowData。这必须根据您拥有的不同列结构手动完成。

    【讨论】:

      猜你喜欢
      • 2016-03-13
      • 2019-03-01
      • 1970-01-01
      • 2019-03-28
      • 2020-03-21
      • 2023-03-13
      • 1970-01-01
      • 2022-12-01
      • 2019-08-11
      相关资源
      最近更新 更多