尝试在ag-grid过滤器文本中显示默认值。在过滤器参数中,我想给用户显示一个默认值,而不仅仅是在结果上显示
from collections import OrderedDict
mylist = ['A','A','B','B','B','C','C','C','C']
mylist = list(OrderedDict.fromkeys(mylist))
print(mylist)
答案 0 :(得分:1)
如果要在过滤器上设置默认值,则可以利用firstDataRendered
事件,并设置初始过滤器模型。
<ag-grid-angular
#agGrid
style="width: 100%; height: 100%;"
id="myGrid"
class="ag-theme-balham"
[columnDefs]="columnDefs"
[defaultColDef]="defaultColDef"
[rowData]="rowData"
(gridReady)="onGridReady($event)"
(firstDataRendered)="onFirstDataRendered($event)"
></ag-grid-angular>
在您的component.ts上,
onFirstDataRendered() {
const yourFilterComponent = this.gridApi.getFilterInstance('athlete');
yourFilterComponent.setModel({
type: 'contains',
filter: 'Phelps'
});
this.gridApi.onFilterChanged();
}
我已经在here上创建了一个演示。
答案 1 :(得分:0)
以上答案的一点点变化对我来说都是有效的。在.ts中,setModel()在apiGrid中使用了 setFilterModel 。
<ag-grid-angular
#agGrid
style="width: 100%; height: 100%;"
id="myGrid"
class="ag-theme-balham"
[columnDefs]="columnDefs"
[defaultColDef]="defaultColDef"
[rowData]="rowData"
(gridReady)="onGridReady($event)"
(firstDataRendered)="onFirstDataRendered($event)"
></ag-grid-angular>
在您的component.ts上,
onFirstDataRendered() {
this.gridApi.setFilterModel({
"year": {
filterType: 'set',
values: ["2010"],
}
})
this.gridApi.onFilterChanged();
}