问题
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
回答1:
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
回答2:
getRowHeight()
is not supported in infinite row model. getRowHeight only works with the InMemoryRowModel
来源:https://stackoverflow.com/questions/44820410/getrowheight-not-working-with-rowmodeltype-infinite-with-latest-ag-grid-ve