How to Programmatically Filter ag-Grid Columns in Angular

You can easily control the column filtering in ag-Grid by using the getFilterInstance and setModel methods associated to the column you need filtering. Once done, remember to call onFilterChanged to apply your changes.

// a list of all your items you want to filter // make sure to create a list of strings // a list of numbers won't work const listOfItems = data.map((row) => row.ComeColumnItem.toString()) // get the filter instance per column const filterInstance = this.gridApi?.getFilterInstance('YourColumnName') // get the existing model in-case you want to modify it const model = this.gridApi?.getModel() // or set a new one filterInstance?.setModel({ type: 'set', values: listOfItems }) // remember to apply the changes when done! this.gridApi?.onFilterChanged()
Code language: TypeScript (typescript)
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments