Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use value of the filter field in ag-grid in Angular 2

I'm making a project with ag grid. But I want to get the input text from the user in the filter field. I need the input from the filter from the user to make an http call. I searched on the website but couldn't get an answer.


1 Answers

Assuming you're using Angular 2 components for this, take a look at the PartialMatchFilterComponent in the examples project.

@Component({
    selector: 'filter-cell',
    template: `
        Filter: <input style="height: 10px" #input (ngModelChange)="onChange($event)" [ngModel]="text">
    `
})
class PartialMatchFilterComponent implements AgFilterComponent {
... rest of the class

The in the onChange method you could fire off your requests as the user typed (you'd probably want to add some sort of debounce here):

onChange(newValue):void {
    if (this.text !== newValue) {
        this.text = newValue;
        ... fire off your http request here ...
        this.params.filterChangedCallback();
    }
}
like image 107
Sean Landsman Avatar answered Jan 19 '26 19:01

Sean Landsman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!