[英]ag-grid react: gridApi is undefined
I am attempting to use the function sizeColumnsToFit() from the Grid API for my ag-grid table. 我正在尝试将Grid API的函数sizeColumnsToFit()用于我的ag-grid表。 When calling this function, I receive the error that "TypeError: Cannot read property 'sizeColumnsToFit' of undefined" 调用此函数时,出现错误“ TypeError:无法读取未定义的属性'sizeColumnsToFit'”
I am attempting basically recreate the example in this link: https://www.ag-grid.com/javascript-grid-resizing/ but it seems like the onGridReady function is not defining this.gridApi properly 我正在尝试基本上重新创建此链接中的示例: https ://www.ag-grid.com/javascript-grid-resizing/但似乎onGridReady函数未正确定义this.gridApi
...
onGridReady = (params) => {
this.api = params.api;
this.columnApi = params.columnApi;
this.gridApi = params.gridApi;
this.gridColumnApi = params.gridApi;
}
render(){
...
//defining columns and rows
this.gridApi.sizeColumnsToFit();
return (
<div
className="ag-theme-balham"
style={{
height: '100%',
width: '100%
}}>
<AgGridReact
columnDefs={columns}
rowData={rows}
onGridReady= {this.onGridReady}>
</AgGridReact>
</div>
);
}
It appears that this.gridApi is out of the scope of the AgGridReact object if its outside of the render function or within the functions for the ag grid. 如果this.gridApi超出了render函数的范围或位于ag网格的函数之内,则似乎超出了AgGridReact对象的范围。 Instead of the above configuration, I called the function in the onGridReady function and it works just fine! 代替上面的配置,我在onGridReady函数中调用了该函数,它工作得很好!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.