Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Angular Changing Row Color when Preview Button is Clicked

In my code, I have a table and a button for every row where the user can preview the items. Since the table contains a lot of elements, when the preview button is clicked, I want the row color to become yellow. Right now, I couldn’t succeed in that with the way I tried. What should I do to achieve what I want?

enter image description here

HTML:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

<button mat-icon-button class="sidebar-toggle" (click)="preview(row)" [ngClass]="{'yellow' : EditIndex == i}">
<mat-icon>pageview</mat-icon>
</button>

TS:

 preview(labPeriod: ILabPeriod) {
        this.labPeriodPreview = undefined;
        this._labService
            .getLabAnalysisTestResultsList(labPeriod.LabPeriodId)
            .subscribe((response: ILabConditionResult[]) => {
                this.labAnalysis.LabConditionResults = response;
                labPeriod.LabAnalysis = this.labAnalysis;
                this.labPeriodPreview = labPeriod;
                this._fuseSidebarService
                    .getSidebar("analysis-detail-period-preview")
                    .open();
            });
    }

>Solution :

Try to add extra property to row object named isYellow.If has undefined or false value class yellow will not displayed.
HTML:

<button mat-icon-button class="sidebar-toggle" (click)="preview(row)" [ngClass]="{'yellow' : row.isYellow}">
<mat-icon>pageview</mat-icon>
</button>

Ts:

 preview(labPeriod: ILabPeriod) {
//new
//todo loop through all rows and set isYellow to false
labPeriod.isYellow = true;
//new
        this.labPeriodPreview = undefined;
        this._labService
            .getLabAnalysisTestResultsList(labPeriod.LabPeriodId)
            .subscribe((response: ILabConditionResult[]) => {
                this.labAnalysis.LabConditionResults = response;
                labPeriod.LabAnalysis = this.labAnalysis;
                this.labPeriodPreview = labPeriod;
                this._fuseSidebarService
                    .getSidebar("analysis-detail-period-preview")
                    .open();
            });
    }
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading