getRowHeight()在最新的ag-grid版本中不能与rowModelType ='infinite'一起使用 [英] getRowHeight() not working with rowModelType = 'infinite' with latest ag-grid version

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

问题描述

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

I see this Note on ag-grid site:

仅在内存行模型中支持更改行高.使用虚拟分页,视口或企业行模型时,不能使用可变的行高.这是因为这些行模型需要计算出未加载的行的位置,因此需要假定行高是固定的.

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)中得到了很好的支持,因此想知道是否必须有其他替代方法来实现这一目标.

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

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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆