【问题标题】:Custom filter: can I have custom buttons for filter?自定义过滤器:我可以为过滤器设置自定义按钮吗?
【发布时间】:2018-05-06 02:55:45
【问题描述】:

我正在尝试在 上拥有自己的自定义过滤器。
除了Apply 按钮外,我还想为过滤器设置其他按钮。即,如果我可以在某种 UI 中解释这一点,

|--自定义过滤器-------------------.
|过滤文本:_____________ |
| Apply | Clear | Clear All|
|_______________________|

通过使用ag-grid 的默认过滤器组件,我知道如果我在ColDef 中提供filterParams,我可以有两个我需要的按钮。

filterParams: {
    applyButton: true,
    clearButton: true
}

但是另一个自定义 (Clear All) 按钮呢?有什么办法可以实现吗?

【问题讨论】:

    标签: ag-grid angular javascript angular ag-grid ag-grid-ng2


    【解决方案1】:

    经过几个小时的搜索和试错,终于实现了。

    看看这里给出的例子:ag-Grid Angular Custom Filter Component 看看PartialMatchFilterComponent 及其代码。

    在模板和组件的一些代码更新后,我们可以实现它。

    更新模板:

    <button (click)="apply()">Apply</button>
    <button (click)="clear()">Clear</button>
    <!-- any other buttons you want to keep -->
    

    组件代码小更新:只需要在Apply按钮点击时调用this.params.filterChangedCallback()

    apply(): void {
        this.params.filterChangedCallback();
    }
    clear(): void {
        this.text = '';
        this.params.filterChangedCallback();
    }
    onChange(newValue): void {
        if (this.text !== newValue) {
            this.text = newValue;
            // this.params.filterChangedCallback(); - remove
        }
    }
    

    【讨论】:

    • :先生,我的 filterChangedCallback 未定义,你能告诉我为什么未定义吗?
    猜你喜欢
    • 1970-01-01
    • 2011-10-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-17
    • 1970-01-01
    相关资源
    最近更新 更多