Grid Styling - Overwrite style of ag-grid

后端 未结 3 629
粉色の甜心
粉色の甜心 2020-12-04 02:24

I have the following style:

.ag-theme-fresh .ag-row-selected {
    background-color: #bde2e5; 
}`

It comes from a css style file of a theme

相关标签:
3条回答
  • 2020-12-04 02:42

    To override the ag-grid use you need to use ng-deep as the style defined in angular component do not overide ag-grid css

    :host ::ng-deep .ag-header-cell-label {
      justify-content: center;
    }
    

    if you are using sass or scss you could override in the style.scss/sass. this would be applicable at all places

    @import "../node_modules/ag-grid-enterprise/dist/styles/ag-grid.scss";
    @import "../node_modules/ag-grid-enterprise/dist/styles/ag-theme-alpine/sass/ag-theme-alpine-mixin";
    
    .ag-theme-alpine {
      @include ag-theme-alpine(
        (
          // use theme parameters where possible
            alpine-active-color: #c066b2,
        )
      );
        .ag-header-cell-label {
            justify-content: center;
          }
        }
    

    if you have need of doing at a specific grid, prefer custom class and make sub-class for the ag-grid.

    0 讨论(0)
  • 2020-12-04 02:43

    You should use ViewEncapsulation

    Just add to your component encapsulation: ViewEncapsulation.None:

    import { Component, ViewEncapsulation } from "@angular/core";
    
    @Component({
        selector: '....',
        templateUrl: '....',
        styles: [`
            .ag-theme-fresh .ag-row-selected {
                background-color: #1428df !important;
            }
        `],
        encapsulation: ViewEncapsulation.None
    })
    
    0 讨论(0)
  • 2020-12-04 02:58

    You can also apply the styles globally and if you do so it will override the styles for all your ag-Grid components. This might not be an option if you are trying to style the components individually, but it's a good way to give a global base style override.

    Also, you should try to use more specific selectors instead of using important.

    Here is an example:

    .ag-theme-alpine > .ag-row.ag-row-selected {
      background : red;
    }
    
    0 讨论(0)
提交回复
热议问题