Reputation: 321
In my Angular application (styled with Angular Material) I need to show some data using a Material Table.
This table has a sticky header, several rows and a sticky footer.
By default, rows have a height of 62.5px and I'd like to override this value.
How can I achieve that?
I have tried overriding the css style for tr / tr.mat-row / tr.mat-header-row etc, without success. I have tried using ::ng-deep too.
Also, my sticky footer row has a 48px height, which i didn't set!! Does anyone know whats happening?
I'm able to edit the footer row css with ::ng-deep, i have set the font-weight to bold, but when i set the height attribute nothing happens.
::ng-deep tr.mat-footer-row {
border: 1px solid #e7e7e7;
font-weight: bold;
}
Upvotes: 19
Views: 78575
Reputation: 164
With @angular/material@17
you can do the following:
:host {
--mat-table-row-item-container-height: 1rem;
}
If you want to change the header and footer too then you can do it this way:
:host {
--mat-table-header-container-height: 2rem;
--mat-table-row-item-container-height: 1rem;
--mat-table-footer-container-height: 1rem;
}
Upvotes: 0
Reputation: 183
Just add the below line in your .css component file
td {
height: 5rem !important;
}
and it should work...
Upvotes: 0
Reputation: 304
With Angular Material 16
header
.mat-mdc-table .mdc-data-table__header-row {
height: 35px;
}
rows
.mat-mdc-table .mdc-data-table__row{
height: 35px;
}
Upvotes: 4
Reputation: 145880
You can also set it in the mat-row
element in the template to an exact value.
Using minHeight
is better than height
because it overrides the default css.
<mat-row
matRipple
*matRowDef="let row; columns: columnNames"
routerLinkActive="highlighted"
[style.minHeight.px]="100">
</mat-row>
Update for Angular 15 / Material 15:
They've now changed the CSS to use height
instead of min-height
so height.px
would be better. I'm still looking for justification, but my guess would be to try to enforce consistency or perhaps it's performance related.
There's also guidance to just use:
.mat-column-name { height: 100px; } // for column 'name'
Upvotes: 3
Reputation: 11
Use this on your style.css
.mat-row{
height: 10px !important;
}
Upvotes: 0
Reputation: 11
my solution:
.mat-header-row{
max-height: 40px;
height: 40px;
min-height: 40px;
text-align: center;
}
Upvotes: 1
Reputation: 12181
I had a similar problem; in my case, the height of the table was too large relative to the number of rows, so setting the height didn't work. When I adjusted the height to be smaller when I had fewer rows, I was able to set the height again.
Upvotes: 0
Reputation: 19
The answers are correct but if it doesn't work for you, it probably means you have a div or any element inside the table that has a height set to it, and if this height is greater than the row height you won't be able to override it.
Upvotes: 2
Reputation: 31
With material 5
mat-row.mat-row.ng-star-inserted
{ height: 32px !important; }
.mat-row{ min-height: 30px; }
Upvotes: 3
Reputation: 316
On a related point, I had an issue where my mat-table rows were too high, and tried to set the height in CSS to reduce it.
It turned out that the problem was "min-height" had been set on "mat-header-row" and "mat-row" somewhere deep inside material (not in my source code).
The fix was simply:
.mat-header-row, .mat-row {
min-height: 30px;
}
Upvotes: 9
Reputation: 587
It works correctly.
tr.mat-footer-row,
tr.mat-row {
border: 1px solid #e7e7e7;
font-weight: bold;
height: 20px !important;
}
Upvotes: 1
Reputation: 822
To change the height by default (48 px) in mat-table you need to specify a class for every row in the html, for example, when you define the rows:
<tr mat-row *matRowDef="let row; columns: displayedCol;" class="table-row"></tr>
Then you can override the height, setting in your main css file the class 'table-row' with a specific height, for example:
.table-row {
height: 30px !important;
}
We prove this with angular 7 and angular material version 7.3.7.
Regards
Upvotes: 12
Reputation: 393
Try adding it out on your styles.scss.
tr.mat-footer-row {
border: 1px solid #e7e7e7;
font-weight: bold;
height: #px !important;
}
Upvotes: 18
Reputation: 151
You could specify the height of the table footer in tr.mat-footer-row
.
tr.mat-footer-row {
height: 100px;
}
Here is StackBlitz example https://stackblitz.com/angular/gjjjdpjqvvde?file=app%2Ftable-sticky-footer-example.css
Upvotes: 0