📜  ag-Grid:尝试调用 sizeColumnsToFit() 但网格以零宽度返回,也许网格在屏幕上还不可见? - 无论代码示例

📅  最后修改于: 2022-03-11 15:00:36.755000             🧑  作者: Mango

代码示例2
import { Directive, HostListener } from '@angular/core';

@Directive({
  selector: '[ag-grid-resize]'
})
export class AgGridResizeDirective {
  private gridApi;

  @HostListener('window:resize')
  onResize() {
    if (!this.gridApi) return;

    setTimeout(() => {
      this.gridApi.sizeColumnsToFit();
    });
  }

  @HostListener('gridReady', ['$event'])
  onGridReady(params) {
    this.gridApi = params.api;

    params.api.sizeColumnsToFit();
  }
}