Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/33.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Ag grid sizeColumnsToFit仅当总栅格宽度中有可用空间时才适用_Javascript_Angular_Ag Grid_Ag Grid Ng2_Ag Grid Angular - Fatal编程技术网

Javascript Ag grid sizeColumnsToFit仅当总栅格宽度中有可用空间时才适用

Javascript Ag grid sizeColumnsToFit仅当总栅格宽度中有可用空间时才适用,javascript,angular,ag-grid,ag-grid-ng2,ag-grid-angular,Javascript,Angular,Ag Grid,Ag Grid Ng2,Ag Grid Angular,是否有一些功能可用于调整列宽以适应整个网格(基本上调用以下 api.sizeColumnsToFit() 只有当没有足够的标题来填充总宽度中的可用空白时。我知道有点晚了,但你知道……太晚总比不到好;-) /** *调整列的大小以适应网格的宽度 *@param allowShrink如果为false,则在没有“空”水平空间时,不会调整列的大小 */ public resizeColumnsToFit(allowShrink=true){ if(this.gridApi){ 如果(允许收缩){ th

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

api.sizeColumnsToFit()


只有当没有足够的标题来填充总宽度中的可用空白时。

我知道有点晚了,但你知道……太晚总比不到好;-)

/**
*调整列的大小以适应网格的宽度
*@param allowShrink如果为false,则在没有“空”水平空间时,不会调整列的大小
*/
public resizeColumnsToFit(allowShrink=true){
if(this.gridApi){
如果(允许收缩){
this.gridApi.sizeColumnsToFit();
}否则{
/**
*这是一个“黑客”——无法使用
*公共网格api-我们必须在这里使用内部工具。
*可能在将来的版本中,这些API中的一些会发生变化
*/
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”]。GetWidthOfcLSINList(列);
如果(使用宽度<可用宽度){
this.gridApi.sizeColumnsToFit();
}
}
}
}
可以使用此方法有条件地调整网格列的大小。如果在有水平滚动条时不想调整列的大小,请使用
resizeColumnsToFit(false)

学分:

  /**
   * 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();
        }
      }
    }
  }