we are using Angular Material table for our app:
<mat-row *matRowDef="let row; columns: displayedColumns;"></mat-row>
could you please to show how to highlight a row on mouse hover?
we are using Angular Material table for our app:
<mat-row *matRowDef="let row; columns: displayedColumns;"></mat-row>
could you please to show how to highlight a row on mouse hover?
Add some CSS with the :hover
selector to the mat-row
elements:
.mat-row:hover {
background-color: red;
}
You can do this styling the component in your theme file:
@mixin newName-theme($dark-theme)
mat-table tbody tr:hover{
cursor: pointer;
background: #b4b4b433;
}
@include newName-theme($dark-theme);
you can find more examples here
in my case .mat-row:hover didn't work, it was highlighting the whole table. this works for me:
tr.mat-row:hover {
background-color: yellow;
}
Angular Material currently has that feature here but if you want to stylize more, here is my solution
Angular 15 changed this slightly. I'm now using:
tr.mat-mdc-row:hover {
background-color: yellow;
}
If you use Angular material > 15 and also .css style file for components, this could be helpful
.mat-mdc-table .mdc-data-table__row:hover{
background-color: rgba(236, 236, 236, 0.514) !important;
}
This worked for me. I applied Bootstrap 4 class .table-hover
to Angular material table.
<table class="table-hover" mat-table>...</table>
For me neither of those worked in Angular 15, had to set background color for <table>
and then change it for <mat-row>
and <mat-header-row>
(it seems that it already has hover but in same background color):
.table {
background-color: whitesmoke;
}
.header-row {
background-color: white;
}
.element-row {
background-color: white;
}
and assign those classes to mentioned elements
Thanks to B.Habibzadeh post here
for me this was enough
.mat-mdc-row:hover {
background-color: red !important
}
And when you use your own class for all rows, even this worked for me:
.myRowClass:hover {
font-weight: bold;
background-color: red !important
}
Hope this will help someone who has issues in new Angular version.