对于想知道为什么会在 Angular 中发生这种情况的人:
我遇到了同样的问题,我正在动态设置 enableSorting 和其他布尔值,但在设置 columnDefs 之后。由于这种初始化顺序, enableSorting 不起作用。
我在 columnDefs 之前首先初始化了我的布尔字段,它就像一个魅力:
ngOnInit(): void {
/* table setting should be initialed before setting data
{
"tableHeight": 300,
"tableClass": "ag-theme-balham",
"enableSorting": true,
"animateRows": true,
"dragDrop": true,
"enableColResize": true,
"sortingOrder": ["desc", "asc", null]
}
*/
this.configService.getGeneralTableData().subscribe((x) => {
this.generalTableSettings = x;
} );
this.configService.getTableHeaderColumnSettings().subscribe((x) => {
this.columnDefs = x;
});
}
<ag-grid-angular
#agGrid
style="width: 100%; height: 400px;"
id="myGrid"
[columnDefs]="columnDefs"
[class]="generalTableSettings?.tableClass"
[enableSorting]="generalTableSettings?.enableSorting"
[animateRows]="generalTableSettings?.animateRows"
[suppressDragLeaveHidesColumns]="generalTableSettings?.dragDrop"
[enableColResize]="generalTableSettings?.enableColResize"
[sortingOrder]="generalTableSettings?.sortingOrder"
(gridReady)="onGridReady($event)"
></ag-grid-angular>