最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin1浏览0评论

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.

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

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

};

Here is My Plunkr where I tried to use getRowHeight() but it did not work.

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.

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

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

};

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

Share asked Jun 29, 2017 at 8:49 undefinedundefined 3,63214 gold badges55 silver badges94 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 9

getRowHeight() is not supported in infinite row model. getRowHeight only works with the 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

发布评论

评论列表(0)

  1. 暂无评论