getRowHeight() 不适用于 rowModelType = 'infinite' 和最新的 ag-grid 版本

getRowHeight() not working with rowModelType = 'infinite' with latest ag-grid version

我在 ag-grid 网站上看到这条注释:

Changing the row height is only supported in the in memory row model. You cannot use variable row height when using virtual paging, viewport or enterprise row models. This is because these row models need to work out the position of rows that are not loaded and hence need to assume the row height is fixed.

但是 getRowHeight() 在以前的版本中得到了很好的支持 (7.x),所以想知道是否有一些替代方法可以实现它。

我在以前版本的 ag-grid 中使用 rowModelType='pagination'。但由于 rowModelType='pagination' 已弃用,我将其替换为 rowModelType='infinite'。 但是有了这个,getRowHeight() 就没有像网站上提到的那样工作了。

是否有其他方法可以实现此目的。 我的网格选项:

var gridOptions = {
floatingFilter:true,
debug: true,
enableServerSideSorting: true,
enableServerSideFilter: true,
enableColResize: true,
rowSelection: 'single',
rowDeselection: true,
columnDefs: columnDefs,
rowModelType: 'infinite',
paginationPageSize: 10,
cacheOverflowSize: 2,
maxConcurrentDatasourceRequests: 2,
infiniteInitialRowCount: 1,
maxBlocksInCache: 2,
//rowHeight: 5,
getRowNodeId: function(item) {
    return item.id;
},
getRowHeight: function(params){
  return 300;
}

};

这是我的 Plunkr,我在其中尝试使用 getRowHeight() 但它不起作用。 https://plnkr.co/edit/P6fnVz4ud1A68khuqDtx?p=preview

无限行模型不支持

getRowHeight()getRowHeight 仅适用于 InMemoryRowModel

获取数据后可以执行下面的代码:

setRowsHeight(){
    let gridHeight = 0;

    this.gridOptions.api.forEachNode(node => {
        let rowHeight = this.gridOptions.getRowHeight(node);

        node.setRowHeight(rowHeight);
        node.setRowTop(gridHeight);

        gridHeight += rowHeight;
    });
    if (!gridHeight) {
        return;
    }

    let elements = this.el.nativeElement.getElementsByClassName('ag-body-container');
    if (elements) {
        this.renderer.setElementStyle(elements[0], 'height', `${gridHeight}px`)
    }
}

希望对你有所帮助 对我来说它解决了问题