Custom filter: can I have custom buttons for filter?

随声附和 提交于 2019-12-11 15:27:17

问题


I am trying to have my own custom filter on ag-grid angular.
Apart from Apply button, I also want to have other buttons for the filter. i.e. if I can explain this in some sort of UI,

|--Custom Filter-------------------.
| Filter Text: _____________ |
| Apply | Clear | Clear All|
|_______________________|

By using default filter component of ag-grid, I know that I can have two buttons I need if I provide filterParams in ColDef.

filterParams: {
    applyButton: true,
    clearButton: true
}

But what about the other custom (Clear All) button? Is there any way I can achieve it?


回答1:


Achieved it after few hours of search and trial-error.

Have a look at the example given here: ag-Grid Angular Custom Filter Component Have a look at the PartialMatchFilterComponent and its code.

After some code updates for template and component, we can achieve it.

Update the template:

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

Little update in the component code: Just need to call this.params.filterChangedCallback() on Apply button click.

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
    }
}


来源:https://stackoverflow.com/questions/47433517/custom-filter-can-i-have-custom-buttons-for-filter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!