Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular - Override CSS of swimlane/ngx-datatable

I need to remove the padding from ngx-datatable header cells and body cells.

My actual solution looks like this:

.datatable-body-cell {
  padding: 0 !important;
}

.datatable-header-cell {
  padding-top: 0 !important;
  padding-bottom: 0 !important;
}

calendar.component.scss

@Component({
  templateUrl: './calendar.component.html',
  styleUrls: ['./calendar.component.scss'],
  encapsulation: ViewEncapsulation.None,
  changeDetection: ChangeDetectionStrategy.OnPush,
})

calendar.component.ts

The problem I encountered is that I need to disable the ViewEncapsulation override the ngx-datatable CSS classes datatable-body-cell and datatable-header-cell. Since I use the ngx-datatable in other components as well, the CSS remains overridden when I navigate to the other components. Only when I refresh the CSS in the other components is shown as it should.

Are there any other possibilities to override CSS of a library in a component without affecting the other components?

I'm using Angular 5.

like image 319
Moriz Martiner Avatar asked May 09 '18 07:05

Moriz Martiner


1 Answers

Keep default component encapsulation and use ng-deep

:host ::ng-deep .datatable-body-cell {
  padding: 0 !important;
}

https://angular.io/guide/component-styles#deprecated-deep--and-ng-deep

like image 96
David Avatar answered Sep 28 '22 03:09

David