【问题标题】:Not able to filer using custom floating filter in ag grid无法在 ag 网格中使用自定义浮动过滤器进行过滤
【发布时间】:2019-06-06 13:24:50
【问题描述】:

我在我的 angular2+ 应用程序中实现了 ag 网格,过滤器对我来说工作正常,但对于某些字段我需要自定义过滤器,因为这些字段不是主数组中的直接字段,例如

abc = [
    xyz_field,
    inner_parent_array: [{inner_field: 60}]
]

我想通过名为 inner_field 的字段进行过滤,但无法使用自定义过滤器进行过滤

这是来自 floatingfiltercomponent 的代码

private params: IFilterParams;
private valueGetter: (rowNode: RowNode) => any;
public text: string = '';

@ViewChild('input', {read: ViewContainerRef}) public input;

agInit(params: IFilterParams): void {
    this.params = params;
    this.valueGetter = params.valueGetter;
    console.log(this.params);
}

isFilterActive(): boolean {
    return this.text !== null && this.text !== undefined && this.text !== '';
}

doesFilterPass(params: IDoesFilterPassParams): boolean {
    console.log(params.node);
    return this.text.toLowerCase()
        .split(" ")
        .every((filterWord) => {
            return this.valueGetter(params.node).toString().toLowerCase().indexOf(filterWord) >= 0;
        });
}

getModel(): any {
    return {value: this.text};
}

setModel(model: any): void {
    this.text = model ? model.value : '';
}

ngAfterViewInit(params: IAfterGuiAttachedParams): void {
    setTimeout(() => {
        this.input.element.nativeElement.focus();
    })
}

onChange(newValue): void {
    if (this.text !== newValue) {
        this.text = newValue;
        console.log(this.params);
        this.params.filterChangedCallback();
    }
}

但它给出了错误,this.params.filterChangedCallback 不是一个函数,我不确定如何解决这个问题

过滤器对 xyz_field 工作正常,但对 inner_field 不工作

这是我想做的活生生的例子

https://plnkr.co/edit/euuPnjpQ2IwtbKRYTXIv?p=preview

【问题讨论】:

标签: angular ag-grid ag-grid-angular


【解决方案1】:

AG-Grid 支持帮助我找到这个, 在列定义中使用 valueGetter 而不是 valueFormatter

【讨论】:

  • 我不明白这一点:使用“valueGetter”如何突然使“filterChangedCallback 不是函数”的错误消失?
猜你喜欢
  • 1970-01-01
  • 2020-04-11
  • 2020-08-07
  • 2019-06-23
  • 2017-01-14
  • 1970-01-01
  • 2019-03-21
  • 2017-10-17
  • 2023-03-19
相关资源
最近更新 更多