简体   繁体   English

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

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

I see this Note on ag-grid site:我在 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.这是因为这些行模型需要计算未加载的行的位置,因此需要假设行高是固定的。

But getRowHeight() was well supported in previous releases(7.x), so was wondering there must be some alternate way to achieve that.但是 getRowHeight() 在以前的版本 (7.x) 中得到了很好的支持,所以想知道是否必须有一些替代方法来实现这一点。

I was using rowModelType='pagination' with previous versions of ag-grid.我在以前版本的 ag-grid 中使用了 rowModelType='pagination'。 But Since rowModelType='pagination' is deprecaded, I replaced this with rowModelType='infinite'.但由于 rowModelType='pagination' 已弃用,我将其替换为 rowModelType='infinite'。 But with this, the getRowHeight() is not working as mentioned in there website.但是有了这个, getRowHeight() 不能像那里的网站上提到的那样工作。

Is there an alternate way to achieve this.有没有替代方法来实现这一目标。 My Grid Options:我的网格选项:

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;
}

}; };

Here is My Plunkr where I tried to use getRowHeight() but it did not work.这是我的 Plunkr,我尝试使用 getRowHeight() 但它没有用。 https://plnkr.co/edit/P6fnVz4ud1A68khuqDtx?p=preview https://plnkr.co/edit/P6fnVz4ud1A68khuqDtx?p=preview

getRowHeight() is not supported in infinite row model.无限行模型不支持getRowHeight() getRowHeight only works with the InMemoryRowModel getRowHeight仅适用于InMemoryRowModel

you can do the code below after getting the data:获取数据后,您可以执行以下代码:

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`)
    }
}

I hope it will help you for me it resolved the issue我希望它能帮助你解决问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM