AgGridReact不对数据更改重新渲染

问题描述:

我将rowData和columnDefs作为道具传递。网格加载正常。但是,当数据发生变化时,网格不会重新渲染。它来到父组件的呈现,并传递给AgGridReact。但是,仍然没有得到重新渲染。AgGridReact不对数据更改重新渲染

由于它是一个完整的应用程序作出反应,我已经添加代码在https://github.com/jintoppy/ag-grid-upgrade

主代码如下。

<AgGridReact 
     // properties 
     columnDefs={this.state.columnDefs} 
     rowData={this.props.data} 

     // events 
     onGridReady={this.onGridReady}> 
</AgGridReact> 

不知道你是否得到解决这个问题。我有一个解决方案。

即使我之前有过这个问题,当我通过道具传递rosData到AgGridReact,然后我尝试使用setRowData(rows)API函数更新行。

一旦你的网格准备好了,你的gridOptions也会有api,这样你就可以通过调用gridOptions.api来访问Ag-grid API,或者你可以像下面那样在你的onGridReady方法中创建this.api。

onGridReady(params)const rowData = this.props.rows;

this.api = params.api; 

if (rowData.length > 0 && this.api) { 
    this.api.setRowData(rowData); 
} 

}

,你需要调用samething在componentWillReceiveProps

componentWillReceiveProps(nextProps) { 

    if (!isEqual(this.props.rows, nextProps.rows) && this.api) { 

     this.api.setRowData(nextProps.rows); 
    } 
    } 

那么你可以从组件删除rowData道具

<AgGridReact 
    // properties 
    columnDefs={this.state.columnDefs} 

    // events 
    onGridReady={this.onGridReady}> 
</AgGridReact> 

希望这有助于...