AGGrid with react,调用this.gridApi.sizeColumnsToFit();不适合列

时间:2018-03-15 01:55:56

标签: javascript css reactjs ag-grid ag-grid-react

我的问题是我的网格根本不会保持代表性,或者如果我尝试创建一个网格而不是很多列,整个网格看起来很奇怪。我希望它伸展到它的容器宽度。这就是我所期望的尺寸.ColumsToFit要做的事情。我收到警告:s但我怎么解决这个问题。例如,我从reducer加载数据,因此会发生重新渲染,或者当我的数据处于获取状态时,我有一个加载微调器。你们采取什么模式来解决这个问题?

以下是一个例子:enter image description here

site

继承我的渲染方法:

ag-Grid: tried to call sizeColumnsToFit() but the grid is coming back with zero width, maybe the grid is not visible yet on the screen?
编辑:我怀疑所有发生的事情,网格合法并不知道onGridReady中的宽度,因为dom还没有完成加载,但其他一切都已初始化。如果我这样做:onGridReady(params) { const { mode } = this.props; this.gridApi = params.api; this.gridApi.mode = mode; this.columnApi = params.columnApi; this.gridApi.addDispatcher = this.props.add; this.gridApi.deleteDispatcher = this.props.delete; this.gridApi.updateDispatcher = this.props.update; console.log(window.innerWidth); this.sizeToFit(); window.onresize = () => { this.gridApi.sizeColumnsToFit(); }; } 在onGridReady(params){...}它会工作,但会有延迟,并不是每个人的浏览器都以相同的速度运行。处理这个问题的任何范例?

1 个答案:

答案 0 :(得分:2)

您可以使用onFirstDataRendered事件,然后调用sizeColumnsToFit。您可以检查文档here