【发布时间】:2019-04-30 01:33:06
【问题描述】:
- 我正在使用带有多个选项的 Angular 材质选择。
- 每次选择或取消选择一个选项时,我都会调用一个选项 过滤表中的数据并仅显示那些 已选中。
这是 mat-select 的代码。
<mat-form-field>
<mat-select placeholder="RequestID" id = "filter-check-box" multiple>
<mat-option (onSelectionChange) = "RequestIDCheckboxFilter($event, RequestID)"
*ngFor="let RequestID of RequestIDArray" [value]="RequestID">{{RequestID}}</mat-option>
</mat-select>
- 这是 RequestIDArray 的定义:
RequestIDArray: string[] = ['REQ001', 'REQ002', 'REQ003', 'REQ004'];
这就是RequestIDCheckboxFilter函数的定义。 ReqIDFilter 是我存储当前检查的值的数组。 :
RequestIDCheckboxFilter(event, text: string) {
var CheckboxFilterComponent = this.gridApi.getFilterInstance("requestID");
if(event.isUserInput) {
var index = this.ReqIDFilter.indexOf(text);
if(index == -1) {
this.ReqIDFilter.push(text);
}
else {
this.ReqIDFilter.splice(index, 1);
}
}
for(var i = 0; i < this.ReqIDFilter.length; i++) {
CheckboxFilterComponent.setModel({
type: "equals",
filter: this.ReqIDFilter[i]
})
}
this.gridApi.onFilterChanged();
}
执行此操作时,即使选择了多个选项,我也只能看到其中一行。比如说,如果选择了 REQ001 和 REQ002,则只有 REQ001 所在的行可见。我也尝试在 setModel 中使用 for 循环,但这会出错。有什么方法可以过滤表格中的所有值吗?
编辑:我使用的是社区版的 ag-grid。
【问题讨论】:
-
您使用的是社区版还是企业版的 ag-grid?
-
社区版。我会在我的问题中更新它。
标签: angular angular-material ag-grid