How to Programmatically Filter ag-Grid Columns in Angular

0 min read 113 words

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()
Andrew
Andrew

Andrew is a visionary software engineer and DevOps expert with a proven track record of delivering cutting-edge solutions that drive innovation at Ataiva.com. As a leader on numerous high-profile projects, Andrew brings his exceptional technical expertise and collaborative leadership skills to the table, fostering a culture of agility and excellence within the team. With a passion for architecting scalable systems, automating workflows, and empowering teams, Andrew is a sought-after authority in the field of software development and DevOps.

Tags

Recent Posts