gpt4 book ai didi

angular8 - 如何以角度触发ag-grid上的firstDataRendered?

转载 作者:行者123 更新时间:2023-12-04 15:08:54 32 4
gpt4 key购买 nike

我的组件有获取数据的输入我用 firstDataRendered 选择第一行。问题是当输入数据发生变化时网格不会触发事件如何根据我的输入更改触发网格事件?

 <ag-grid-angular
#agGrid
class="ag-theme-alpine"
style="width: 100%; height: 500px"
[rowData]="flights"
[columnDefs]="columnDefs"
[rowSelection]="'single'"
(gridReady)="onGridReady($event)"
(firstDataRendered)="onFirstDataRendered($event)"
>
</ag-grid-angular>

import {
Component,
Input,
OnChanges,
OnInit,
SimpleChanges,
} from '@angular/core';
import { Flight } from './model/flight.interface';

@Component({
selector: 'app-worker-flights-list',
templateUrl: './worker-flights-list.component.html',
styleUrls: ['./worker-flights-list.component.css'],
})
export class WorkerFlightsListComponent implements OnInit, OnChanges {
@Input() flights: Flight[] = [];
gridApi: any;
rendered: boolean;
columnDefs = [
{ headerName: 'Flight Number', field: 'num' },
{ headerName: 'Origin', field: 'from' },
{ headerName: 'Origin Date', field: 'from_date' },
{ headerName: 'Destination', field: 'to' },
{ headerName: 'Destination Date', field: 'to_date' },
];
constructor() {}
ngOnChanges(changes: SimpleChanges): void {
if (changes['flights'] && this.rendered) {
// this.gridApi.api.getDisplayedRowAtIndex(0).setSelected(true);
}
}

ngOnInit(): void {}
onGridReady(grid: any): void {
debugger;
this.gridApi = grid;
}
onFirstDataRendered(params: any): void {
this.rendered = true;
this.gridApi.api.getDisplayedRowAtIndex(0).setSelected(true);
}
}

最佳答案

firstDataRendered 事件只会在第一次 呈现数据时触发,而不是每次呈现或更新数据时触发。查看事件定义 here .

一个解决方案是像这样利用 rowDataChanged 事件:

onRowDataChanged(params: any): void {
this.rendered = true;
params.api.getDisplayedRowAtIndex(0).setSelected(true);
}

查看演示 here

关于angular8 - 如何以角度触发ag-grid上的firstDataRendered?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65568454/

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