Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ag-grid : How to set custom background color in column header?

I'm using ag-grid with Angular 4. I want to be able to change the background color of individual column headers during runtime.

It seems that I have to use headerComponentFramework property in coldefs, but I have no idea how to use this. Anybody has an idea?

regards, Alex

like image 707
Seeschorle Avatar asked May 11 '17 11:05

Seeschorle


Video Answer


2 Answers

If using Sass then setting the header-background-color theme parameter should work.

The example below assumes you are using the alpine theme.

@import "~ag-grid-community/src/styles/ag-grid.scss";
@import "~ag-grid-community/src/styles/ag-theme-alpine/sass/ag-theme-alpine-mixin";

.ag-theme-alpine {
    @include ag-theme-alpine((
        header-background-color: deeppink
    ));
}

https://www.ag-grid.com/javascript-grid-themes-customising/#setting-parameters-using-sass

like image 174
yohosuff Avatar answered Sep 20 '22 18:09

yohosuff


If you have a predefined set of colors for the header, I would use the headerClass option:

defaultColDef: {
  headerClass: function(params) {
    // logic to return the correct class
    return 'header-one';
  }
}

Then in css use the background-color property:

.header_one {
  background-color: red;
}

See the following example where clicking on a cell changes the header color:

https://stackblitz.com/edit/ag-grid-header-color-dynamic?file=index.js

like image 41
Matt Nienow Avatar answered Sep 21 '22 18:09

Matt Nienow