首页 > 解决方案 > 动态添加 colDefs

问题描述

我正在尝试在单击按钮时以编程方式添加列定义,而不是在我的 ReactJS 页面中对其进行硬编码。

{
    headerName: "Product1",
    resizable: true,
    wrapText: true,
    cellStyle: {
        'white-space': 'normal'
    },
    autoHeight: true,
    hide: true,
    cellRendererFramework.MyCustomColumnRenderer
}

不确定如何实施?谢谢你的帮助。

标签: reactjsag-grid

解决方案


利用setColumnDefs(columnDefs)

    const columnDefs = getColumnDefs();
    columnDefs.forEach(function (colDef, index) {
      colDef.headerName = 'Abcd';
    });
    this.gridApi.setColumnDefs(columnDefs);

https://plnkr.co/edit/0ctig4P2yzPjhycB


推荐阅读