gpt4 book ai didi

javascript - Ag grid sizeColumnsToFit 仅当总网格宽度中有可用空间时才使用

转载 作者:行者123 更新时间:2023-12-02 09:07:15 29 4
gpt4 key购买 nike

是否有一些函数可以调整列宽以适应整个网格(基本上调用以下

api.sizeColumnsToFit()

仅当没有足够的标题来填充总宽度中可用的空白空间时。 enter image description here

最佳答案

我知道有点晚了,但你知道...迟到总比不做好;-)

  /**
* resizes the columns to fit the width of the grid
* @param allowShrink if false, columns will NOT be resized when there is no "empty" horizontal space
*/
public resizeColumnsToFit(allowShrink = true) {
if (this.gridApi) {
if (allowShrink) {
this.gridApi.sizeColumnsToFit();
} else {
/**
* this is a "hacK" - there is no way to check if there is "empty" space in the grid using the
* public grid api - we have to use the internal tools here.
* it could be that some of this apis will change in future releases
*/
const panel = this.gridApi["gridPanel"];
const availableWidth = this.gridApi["gridPanel"].eBodyViewport.clientWidth;
const columns = this.gridApi["gridPanel"]["columnController"].getAllDisplayedColumns();
const usedWidth = this.gridApi["gridPanel"]["columnController"].getWidthOfColsInList(columns);

if (usedWidth < availableWidth) {
this.gridApi.sizeColumnsToFit();
}
}
}
}

您可以使用此方法有条件地调整网格列的大小。如果您不想在存在水平滚动条时调整列大小,请使用 resizeColumnsToFit(false)

信用:https://github.com/ag-grid/ag-grid/issues/1772

关于javascript - Ag grid sizeColumnsToFit 仅当总网格宽度中有可用空间时才使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55587083/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com