1

嗨,有没有办法调用他们在列定义的 autoHeight 中使用的函数?我有一个功能,可以根据备注一列的内容展开和折叠行。在初始加载时,行高仅适用于 2 个文本行。当我单击展开时,该行将根据备注列内容展开。他们的 autoHeight 正在处理初始加载以根据内容扩展行,但我在初始加载时不需要它。当我尝试通过单击展开按钮来更新它然后调用 resetRowHeights 时没有任何反应。我有一个临时解决方案,我计算文本的长度等。它适用于正常情况,但问题是如果他们将列的宽度更改为更小然后扩展。我尝试获取文本与列的比率以动态计算它,但计算失败。

下面是我当前用于计算行的代码。

expandView() {
        this.isExpand = true;

        this.gridApi.forEachNode((rowNode: RowNode) => {
            let ulRemarksTotalRowHeight = 0;
            let customerRemarksTotalRowHeight = 0;
            let ulRemarksList = [];
            let customerRemarksList = [];

            const ulRemarks = rowNode.data.map_ul_remarks;
            const customerRemarks = rowNode.data.map_cust_remarks;

            if (ulRemarks) {
                ulRemarksList = rowNode.data.map_ul_remarks.split('\n');
            }

            if (customerRemarks) {
                customerRemarksList = rowNode.data.map_cust_remarks.split('\n');
            }

            if (ulRemarksList) {
                for (let i = 0; i < ulRemarksList.length; i++) {
                    const display = ulRemarksList[i];

                    // 28 - Default height value(in px) of one row in ag-Grid;
                    // 19 - Maximum text length for one row in ag-Grid(Initial Load/Without Resizing the Column of UL and Customer Remarks);
                    const ulRemarksHeight = Math.ceil(display.length / 19) * 28;
                    ulRemarksTotalRowHeight += ulRemarksHeight;
                }
            }

            if (customerRemarksList) {
                for (let i = 0; i < customerRemarksList.length; i++) {
                    const display = customerRemarksList[i];

                    // 28 - Default height value(in px) of one row in ag-Grid;
                    // 19 - Maximum text length for one row in ag-Grid(Initial Load/Without Resizing the Column of UL and Customer Remarks);
                    const customerRemarksHeight = Math.ceil(display.length / 19) * 28;
                    customerRemarksTotalRowHeight += customerRemarksHeight;
                }
            }

            const largestHeight = Math.max(ulRemarksTotalRowHeight, customerRemarksTotalRowHeight);

            if (largestHeight !== 0 && largestHeight > 56) {
                rowNode.setRowHeight(largestHeight);
            } else {
                // 2 rows = 56px;
                rowNode.setRowHeight(56);
            }
        });
        this.gridApi.onRowHeightChanged();
    }
4

0 回答 0