2

I have a span element in ngx datatable. I want to change the css class dynamically based on the value.

Here's my html code:

<ngx-datatable #orderinvoice class="bootstrap" [rows]="invoiceSource" [headerHeight]="50" [footerHeight]="50"
            [rowHeight]="'45'" [scrollbarH]="true" [columnMode]="'force'" [limit]="limit"
            [sorts]="[{prop: 'sNo', dir: 'asc'}]">
            <ngx-datatable-column *ngFor="let column of displayColumns" [name]="column.name">
                <ng-template let-column="column" ngx-datatable-header-template>
                    <span>{{column.name}}</span>
                </ng-template>
                <ng-template ngx-datatable-cell-template let-rowIndex="rowIndex" let-value="value" let-row="row">
                    <span [ngClass]="{'label label-primary': row[column.value] === 'Complete', 'label label-warning':row[column.value] === 'Processing' }"
                    *ngIf="column.name !== 'Actions'">{{row[column.value]}}</span>
                    <span *ngIf="column.name === 'Actions'">
                        <button class="btn btn-success mr-1 btn-fab" placement="top"
                            data-controls-modal="custom-modal-2" data-toggle="modal" data-backdrop="static"
                            data-keyboard="false" ngbTooltip="View" (click)="SerachInvoice(row , 'custom-modal-2')">
                            <i class="ft-eye"></i>
                        </button>
                        <button class="btn btn-primary mr-1 btn-fab" placement="top" ngbTooltip="Edit"
                        [disabled]="financeYear"   (click)="edit(row)">
                            <i class="ft-edit"></i>
                        </button>
                        <button class="btn btn-warning mr-1 btn-fab" placement="top" ngbTooltip="Print"
                            (click)="SerachInvoice(row,'printSection')">
                            <i class="fa fa-paper-plane-o"></i>
                        </button>
                    </span>
                </ng-template>
            </ngx-datatable-column>
        </ngx-datatable>

in the above i need to apply class based on condition

 <span [ngClass]="{'label label-primary': row[column.value] === 'Complete', 'label label-warning': row[column.value] === 'Processing' }"

hear class result unable to getting could u please tell me what the cause ??

bellow is the bootstrap classes enter image description here

6
  • hear class unable to loading <- can you please rephrase this and maybe add more details? Commented May 27, 2020 at 8:06
  • could u see now Alex Biro Commented May 27, 2020 at 8:10
  • Sorry, probably my problem, but still, I don't understand the word hear in this context. Try maybe copying the error form the console, or screenshoting it. Commented May 27, 2020 at 8:13
  • And what are the css classes applied to your element? None? Or are they applied and overriden Commented May 27, 2020 at 8:14
  • can you share your table html code please ? Commented May 27, 2020 at 8:28

1 Answer 1

1

Seem to have change from label to badge

Docs

https://getbootstrap.com/docs/4.4/components/badge/

Hack Demo

https://stackblitz.com/edit/angular-ivy-3keqr9

Sign up to request clarification or add additional context in comments.

8 Comments

yes its working supun De silva but all rows data getting with bold text .. i dont want show like that ...
Use a class like follows to remove the font-weight .fw-default { font-weight: inherit !important; } or .fw-default { font-weight: unset !important; } new example stackblitz.com/edit/angular-ivy-2se6yv
everything perfect .. but the problem is using that css font style is different from other grid pages .. could u please suggest the same for all pages ..how can i over come this ?
in the css class set font-weight: 400 !important; instead of font-weight: inherit !important; See if that helps
sorry for interrupting above screens are the diffrece could u please look into that i change css what u said but there is no diffrence ..
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.