简体   繁体   English

如何使用Ag-Grid动态增加行高?

[英]How to dynamically increase the row height using Ag-Grid?

I have a table using ag-Grid. 我有一个使用ag-Grid的表格。 I would like to adjust the row height according to the text in the cell. 我想根据单元格中的文本调整行高。 In documentation https://www.ag-grid.com/javascript-grid-row-height/index.php it was given for specific column. 在文档https://www.ag-grid.com/javascript-grid-row-height/index.php中,它是为特定列提供的。 But in my case any column can have more text. 但就我而言,任何列都可以包含更多文本。 So how to adjust the row height according to the largest text size in any of the column. 因此,如何根据任何一列中最大的文本大小来调整行高。

$scope.gridOptions = {
            angularCompileRows: true,
            enableColResize: true,
            enableSorting: true,
            enableFilter: true,
            groupHeaders: true,
            suppressCellSelection: true,
            columnDefs: cols,
            rowData: statusPageObj.rows,
            onGridReady: opmGridReady,
            angularCompileRows: true,
            headerHeight: 45,
            /*rowHeight: 50,*/
            getRowHeight: function(params) {
               return 50;
            }

        };

step:1 html code 步骤:1个 html代码

<button onclick="setrowHeight(50)">50px</button>

step:2 js code 步骤:2个 js代码

var rowHeight = 25;

function setrowHeight(height) {
    rowHeight = height;
    gridOptions.api.resetRowHeights();
}

watch this : https://embed.plnkr.co/FEK7wtQfVwUXeYjOh6PK/ 看这个https : //embed.plnkr.co/FEK7wtQfVwUXeYjOh6PK/

You can determine the height of the row based on the text-length. 您可以根据文本长度确定行的高度。

gridOptions.getRowHeight = function() {
     return 18 * (Math.floor(params.data.myDataField.length / 45) + 1);
}

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

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