I have a mat-table where I display list of rows. I have a add new button through which user can manually add a row. Working Stackblitz: https://stackblitz.com/edit/angular-axjzov-8zmcnp I want the option to highlight the newly inserted row for 2-3 sec so that the user can see the newly created row. How do I achieve this?
You can add this to the style css
mat-row.mat-row {
animation: highlight 3s;
}
@keyframes highlight {
0% {
background: red
}
100% {
background: none;
}
}
In case you only want to highlight the new rows, you need to define the new row to add a class to them.
So let's say the class name is "highlight".
In the component you add:
export class TableFilteringExample {
//...
newRowIndex = 0;
//...
addElement() {
this.newRowIndex++;
//...
}
}
In the HTML template file:
<!--...-->
<mat-row *matRowDef="let row; columns: displayedColumns; let i = index"
[ngClass]="{'highlight': i < newRowIndex}"></mat-row>
<!--...-->
And in the style file:
.highlight {
animation: highlight 3s;
}
@keyframes highlight {
0% {
background: red
}
100% {
background: none;
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With