我试图添加一个外部过滤器,但首先,它不起作用,现在我的网格没有显示,它停留在加载中,所以我没有过滤器和网格。
目前我正在对数据进行硬编码,首先,我想确保它正常工作,然后我将从API中获取数据。
export class AgreementListComponent implements OnInit {
private gridApi;
private gridColumnApi;
ageType = "";
private columnDefs;
private defaultColDef;
private rowData: [
{
title: 'Agreement 1', status: 'Status 1', type: 'Type 1', effectiveDate: 'February/28/2020',
expirationDate: 'February/28/2020',
upcomingStipulations: 'Upc Stip 1', overdueStipulations: 'Over Stip 1'
},
{
title: 'Agreement 2', status: 'Status 2', type: 'Type 2', effectiveDate: 'February/28/2020',
expirationDate: 'February/28/2020',
upcomingStipulations: 'Upc Stip 2', overdueStipulations: 'Over Stip 2'
}
];
constructor() {
this.columnDefs = [
{ headerName: "Agreement Title", filter: true, field: 'title' },
{ headerName: "Status", filter: 'agTextColumnFilter', field: 'status' },
{ headerName: "Agreement Type", filter: true, field: 'type' },
{ headerName: "Effective Date", filter: true, field: 'effectiveDate' },
{ headerName: "Expiration Date", filter: true, field: 'expirationDate' },
{ headerName: "Upcoming Stipulations", filter: true, field: 'upcomingStipulations' },
{ headerName: "Overdue Stipulations", filter: true, field: 'overdueStipulations' },
]
this.defaultColDef = { filter: true };
}
onGridReady(params) {
this.gridApi = params.api;
this.gridColumnApi = params.columnApi;
this.rowData = this.rowData
}
isExternalFilterPresent() {
return this.ageType != "everyone";
}
externalFilterChanged(newValue) {
console.log('externalFilterChanged')
this.ageType = newValue;
this.gridApi.onFilterChanged();
}
doesExternalFilterPass(node) {
switch (this.ageType) {
case "below30":
return node.data.status = 'Status 1';
default:
return true;
}
}
ngOnInit() {
}
}这是我的Html
<div>
<button (click)="externalFilterChanged('Status 1')">Status 1</button>
</div>
<ag-grid-angular style="width: 100%; height: 400px;" class="ag-theme-balham"
[rowData]="rowData"
[columnDefs]="columnDefs"
[doesExternalFilterPass]="doesExternalFilterPass"
[isExternalFilterPresent]="isExternalFilterPresent"
[animateRows]="true"
[defaultColDef]="defaultColDef"
[enableSorting]="true"
[enableFilter]="true"
(gridReady)="onGridReady($event)">
</ag-grid-angular>我试着遵循这个guide,但是我不明白为什么过滤器之前不能工作,或者为什么我的网格不再显示。
发布于 2020-06-26 19:00:27
发布于 2020-09-02 01:02:14
https://stackoverflow.com/questions/60458634
复制相似问题