Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

567
Vistas
Change background color of certain cell header in ag-grid Angular dynamically

I have an ag grid with the following columns. My requirement is based on the loggedin user role I want to highlight the background color of the columns 'abc'. If the user role is admin then need to change the background-color to green of the column 'abc'. If the role is normal user then I have to change the color to red.

colDefs=[
    abc: {
        headerName: 'ABC',
        field: 'abc',
        colId: 'abc',
        pinned: 'left',
      },
      def:{
        headerName: 'DEF',
        field: 'def',
        colId: 'def',
        pinned: 'left',
      },
     ghi:{
        headerName: 'GHI',
        field: 'ghi',
        colId: 'ghi',
      },
      pqr:{
        headerName: 'PQR',
        field: 'pqr',
        colId: 'pqr',
        editable: false,
      }
]

<ag-grid-angular
  #grid
  [gridOptions]="gridOptions"
  class="ag-theme-balham"
  [columnDefs]="columnDefs"
></ag-grid-angular>

Could you please tell me how can I implement that? I tried following the already asked questions but didnt get the results Dynamic change of cell color with Ag Grid

Also is there any way to add condition to headerName like following?

 headerName: isAdmin ? 'GHI' : 'XYZ',
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

you can use cellClass and cellStyle as described in documentation:

https://www.ag-grid.com/javascript-data-grid/cell-styles/

 {
      headerName: 'header name',
      field: 'abc',
      cellClass: params => {
          return params.value === 'something' ? 'my-class-1' : 'my-class-2';
      },
 },
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda