我有一个agGrid,其中包含使用了refData属性的列。它显示为“是”或“否”,但基础值为“ 1”或“ 0”。我想按数据过滤列,但按“是”或“否”过滤时,它没有任何结果。但是,当我放置基础数据(即1或0)时,过滤器开始工作。
HTML文件
<ag-grid-angular class="ag-theme-balham"
[rowData]="categoryRowData" [columnDefs]="categoryColDef" [domLayout]="domLayout"
(gridReady)="onGridReady($event)">
</ag-grid-angular>
TS文件
export class CategoryComponent implements OnInit{
private domLayout;
private objCategoryEditor = {};
categoryColDef ;
constructor()
{
this.getCategoryMapping();
this.createCategoryColDefinition();
}
ngOnInit() {
this.domLayout = "autoHeight";
}
onGridReady(params: any) {
params.api.sizeColumnsToFit();
params.api.resetRowHeights();
}
createCategoryColDefinition() {
this.categoryColDef = [
{
headerName: 'Is Subcategory', field: 'IsSubcategoryText', resizable: true,filter:true,
editable: function (params: any) {
return true;
},
cellEditor: "agSelectCellEditor",
cellEditorParams: {
values: this.extractValues(this.objCategoryEditor),
},
refData: this.objCategoryEditor,
}
]}
getCategoryMapping()
{
this.objCategoryEditor["0"] = "No";
this.objCategoryEditor["1"] = "Yes";
this.createCategoryColDefinition();
}
extractValues(mappings) {
return Object.keys(mappings);
}
}
按“否”过滤时,它不返回任何行:-
当按0过滤时,它将返回行:-
如何自定义过滤,以便在按“是”或“否”进行过滤时开始返回行? 请对此提供帮助。
答案 0 :(得分:2)
我会在列定义中使用filterValueGetter
-
filterValueGetter: this.customfilterValueGetter
这是customfilterValueGetter
customfilterValueGetter(params) {
if(params.data) {
return this.objCategoryEditor[params.data.IsSubcategoryText];
}
}
根据文档-
filterValueGetter(params)
函数或表达式。获取用于过滤目的的值。
Plunkr here。检出零售价列
答案 1 :(得分:0)
代替使用0和1创建对象键,而是使用yes和No属性本身,如下所示,这将帮助您解决此问题
getCategoryMapping()
{
this.objCategoryEditor["No"] = "No";
this.objCategoryEditor["Yes"] = "Yes";
this.createCategoryColDefinition();
}