【发布时间】:2018-07-29 14:47:02
【问题描述】:
我想在 Angular 2 中过滤本地环境(无服务器端)中的列。用户从每个列的选定菜单中选择一个状态。
我该怎么办?有最佳做法吗?
谢谢!
我的代码:
columnDefs: [
{
headerName: "Job status",
field: "jobStatus",
floatingFilterComponentFramework: HListCellComponent,
floatingFilterComponentParams: {
suppressFilterButton: true,
items: [
{
label: 'All',
value: 'all'
},
{
label: 'Created',
value: 'CREATED'
},
{
label: 'Running',
value: 'RUNNING'
},
...
]
}
},
...
suppressCellSelection: true,
enableRangeSelection: true,
floatingFilter: true,
suppressRowClickSelection: true,
enableColResize: true,
enableFilter: true,
onFilterChanged: (event: FilterChangedEvent) => {
// TODO: How to filter in local environment?
}
}
HListCellComponent是一个创建选中菜单的组件,代码为:
agInit(params: any) {
this.params = params;
const api: GridApi = params.api;
const column: Column = params.column;
this.items = params.items;
this.formControl.valueChanges
.debounce(() => Observable.timer(500))
.map(value => value === 'all' ? null : value)
.subscribe(value => {
const colName = column.getColId();
const a: any = api.getFilterInstance(colName);
if (!a.value) {
a.value = {};
}
a.value[colName] = value;
api.onFilterChanged();
});
}
【问题讨论】: