setColumnDefs对于某些农业电网不起作用 [英] setColumnDefs is not working for some ag-grids
本文介绍了setColumnDefs对于某些农业电网不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的代码中有几个ag-grids,并且 setColumnDefs适用于所有网格,但是当我尝试创建新网格时,出现错误:无法读取未定义的属性 setColumnDefs。
我不知道我在做什么错。
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);
推荐答案
您需要等待网格初始化之后才能使用
you need to wait for the grid to be initialised before the api is ready.
所以您有两个选择:
a)将网格直接放到gridOptions上。
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'
}
]
};
或b)等待网格初始化
vm.newGrid = {
enableSorting: true,
enableColResize: true,
onGridReady: function(params) {
params.api.setColumnDefs(newGridColumns);
}
};
这篇关于setColumnDefs对于某些农业电网不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文