AG网格无限行模型不工作-不能得到网格绘制行,当它在绘制行的中间



当我使用AG网格无限行模型时,我得到以下错误:cannot get grid to draw rows when it is in the middle of drawing rows. Your code probably called a grid API method while the grid was in the render stage. To overcome this, put the API call into a timeout, e.g. instead of api.refreshView(), call setTimeout(function() { api.refreshView(); }, 0).我为无限滚动模型使用的代码是以下错误文本建议:

const onGridReady = (params: any) => {
setGridApi(params.api);
setGridColumnApi(params.columnApi);
if (state && params.columnApi) {
params.columnApi.applyColumnState({ state: state as ColumnState[], applyOrder: true });
}
if (sortModel && params.api) {
params.api.setSortModel(sortModel);
}
if (filterModel && params.api) {
params.api.setFilterModel(filterModel);
}
const updateData = (data: any) => {
const dataSource = {
rowCount: null,
getRows: function (params: any) {
setTimeout(() => {
let lastRow = -1;
if (data.length <= params.endRow) {
lastRow = data.length;
}
params.successCallback(data, lastRow);
}, 500);
},
};
params.api.setDatasource(dataSource);
}
fetchSparepart(`${process.env.REACT_APP_API_HOST}/spareparts?startRow=${params.startRow ?? 0}&endRow=${params.endRow ?? 50}`)
.then(res => updateData(res))
}
<AgGridReact
localeText={AG_GRID_LOCALE_RU}
rowBuffer={0}
rowSelection={'multiple'}
rowModelType={'infinite'}
paginationPageSize={50}
cacheOverflowSize={2}
maxConcurrentDatasourceRequests={1}
infiniteInitialRowCount={50}
maxBlocksInCache={10}
paginationAutoPageSize={true}
pagination={true}
onGridReady={onGridReady}
onSelectionChanged={onSelectionChanged}
onSortChanged={onSortChanged}
onFilterChanged={onFilterChanged}
rowClassRules={rowClassRules}
onRowDoubleClicked={onSelectionChanged}
frameworkComponents={{
booleanCellRenderer: booleanCellRenderer
}}
context={{
methodFromParent
}}
>
....

我在这里错过了什么?

在我的例子中,问题是引入了"rowClassRules",在你的例子中,它可能是一个不同的函数,但出于同样的原因:

函数访问了一个未定义的属性,导致了一个异常,这个异常显然被aggrid静默捕获了。我猜这种方式的标志,它目前正在重绘,从来没有被清除,在下一次迭代时,它检测到渲染仍在进行中,导致上述错误。

=比;调试你的回调函数,其中一个可能坏了。在我的例子中,我从cellClassRules切换到rowClassRules,并错过了"params"参数有不同的结构,即一个数据属性,没有"值"。,所以我突然访问了undefined

最新更新