答案 0 :(得分:1)
我有点晚了,但是你知道...总比不来晚;-)
/**
* 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)
。