setColumnDefs is not working for some ag-grids

倾然丶 夕夏残阳落幕 提交于 2019-12-10 19:35:51

问题


I have several ag-grids in my code and the "setColumnDefs" is working for all the grids, however when I am trying to create a new grid, I am getting the error: Cannot read property 'setColumnDefs' of undefined. I don't know what I'm doing wrong. It seems to work for other ag-grids.

vm.newGrid = {
            enableSorting: true,
            enableColResize: true
        };

var newGridColumns = [
            {
                headerName: 'DATA',
                field: 'data',
            }, {
                headerName: 'PERCENT',
                field: 'percent'
            }
        ];

vm.newGrid.api.setColumnDefs(newGridColumns);

回答1:


you need to wait for the grid to be initialised before the api is ready.

so you have two choices: a) put the grids directly onto the gridOptions

vm.newGrid = {
  enableSorting: true,
  enableColResize: true,
  columnDefs: [
        {
            headerName: 'DATA',
            field: 'data',
        }, {
            headerName: 'PERCENT',
            field: 'percent'
        }
    ]
};

or b) wait for the grid to be initialised

vm.newGrid = {
  enableSorting: true,
  enableColResize: true,
  onGridReady: function(params) {
      params.api.setColumnDefs(newGridColumns);
  }
};


来源:https://stackoverflow.com/questions/35945197/setcolumndefs-is-not-working-for-some-ag-grids

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!