Home > Software engineering >  How to set filter to false in defaultColDef only where headerName === "Action" in ag-grid?
How to set filter to false in defaultColDef only where headerName === "Action" in ag-grid?

Time:01-23

I am able to set filter via gridOptions.defaultColDef.filter but I can't find out how to set the value based on headerName value.

I've tried looping through columnDefs but filter doesn't exists on that type (even though it is settable in columndDefs when I use the component in my app).

gridOptions.columnDefs?.forEach(colDef => { 
  if (colDef.headerName === "Action") colDef.filter = false
}

Any idea how to set set filter to false as default for Action column and having it true for all others?

CodePudding user response:

Set the filter to false in the constructor of your component like you already are. The type error can be relived by setting the type of your colDef value to any, but the correct solution would be to set it to ColDef which can be imported like so:

import { ColDef } from 'ag-grid-community/dist/lib/main';

this.columnDefs?.forEach((colDef: ColDef) => { 
  if (colDef.headerName === "Action") {
    colDef.filter = false
  }
});  

Demo.

  •  Tags:  
  • Related