0

I'm trying to set a background in my entire cell (or my entire row) according to my condition, but the background it placed only at my HTML element.

I already tried put some class at my trying to set the padding 0, I already tried put some div.

HTML

<p-column header="Motivo"  [style]="{width: '100px', 'text-align': 'center'}">
  <ng-template let-movimento="rowData" pTemplate="body">
   <p [ngClass]="{'motivo-SemEfeito': movimento.motivoDesligamentoId == 2}">
       {{ movimento.motivoDesligamento }}
    </p>
  </ng-template>
</p-column>

CSS

.motivo-SemEfeito {
  text-decoration: line-through;
  background: red;
 }
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
paulotarcio
  • 461
  • 1
  • 5
  • 20

2 Answers2

0

You can try this way by using styleClass

HTML

<p-column header="Motivo"  [styleClass]="methodNameForTheClass(data)">

TS

 methodNameForTheClass(data){
   // write your condion here and return class name as string
   return 'className';
}
Abhishek Ekaanth
  • 2,511
  • 2
  • 19
  • 40
0

As shown in the document of NgClass you can put a condition to your class:

<some-element [ngClass]="{'first': true, 'second': true, 'third': false}">...</some-element>

Put the background in your css class for it:

html:

<div [ngClass]="{'red': red, 'blue': !red}">
    <p-column header="Motivo"  [style]="{width: '100px', 'text-align': 'center'}">
      <ng-template let-movimento="rowData" pTemplate="body">
       <p [ngClass]="{'motivo-SemEfeito': movimento.motivoDesligamentoId == 2}">
           {{ movimento.motivoDesligamento }}
        </p>
      </ng-template>
    </p-column>
</div>

css:

.red {
    background: red;
}

ts:

const red = false;
Gaspar
  • 1,515
  • 13
  • 20