本文介绍了getRowHeight()在最新的ag-grid版本中不能与rowModelType ='infinite'一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I see this Note on ag-grid site:

但是getRowHeight()在以前的版本(7.x)中得到了很好的支持,因此想知道是否必须有其他替代方法来实现这一目标.

But getRowHeight() was well supported in previous releases(7.x), so was wondering there must be some alternate way to achieve that.

我在ag-grid的早期版本中使用rowModelType ='pagination'.但是由于不推荐使用rowModelType ='pagination',因此我将其替换为rowModelType ='infinite'.但是,有了这个,getRowHeight()不能像那里的网站所提到的那样工作.

I was using rowModelType='pagination' with previous versions of ag-grid. But Since rowModelType='pagination' is deprecaded, I replaced this with rowModelType='infinite'. But with this, the getRowHeight() is not working as mentioned in there website.

是否有另一种方法可以实现这一目标.我的网格选项:

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

};

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

Here is My Plunkr where I tried to use getRowHeight() but it did not work.https://plnkr.co/edit/P6fnVz4ud1A68khuqDtx?p=preview

推荐答案

您可以在获取数据后执行以下代码:

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 youfor me it resolved the issue

这篇关于getRowHeight()在最新的ag-grid版本中不能与rowModelType ='infinite'一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-25 03:16