简体   繁体   中英

PrimeNG - How to change the style of pTemplate="caption" in p-table for a single component

I'd like to change the background color of the caption cell of my p-table in only one component, how can I do?

I tried <ng-template pTemplate="caption" class="myStyle">

and .myStyle{ background: rgb(9,169,121) !important; } .myStyle{ background: rgb(9,169,121) !important; } in my.component.scss

but it doesn't work.

Help me! Thanks!


Edit: Finally it works! I see the answer of @Antikhippe, but I had to add

:host ::ng-deep { #myTable {
.p-datatable-thead{ background: red;
} .p-datatable .p-datatable-thead > tr > th { background: inherit; } } }

pTemplate="caption" will only fit part of your table header, you have to work on p-datatable-header class:

Try this:

:host ::ng-deep {
  #myTable {
    .p-datatable-header {
      background-color: red;
    }
  }
}

I surrounded p-datatable-header class with #myTable to apply this CSS only for a table with myTable id:

<p-table id="myTable" [value]="products">

See StackBlitz

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM