Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

566
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda