How to change Angular Material Table row height?
Try adding it out on your styles.scss.
tr.mat-footer-row {
border: 1px solid #e7e7e7;
font-weight: bold;
height: #px !important;
}
How do you adjust the height of mat-table header and rows?
As I can see from the Angular Material documentation examples, mat-cells have some padding, try to remove it or adjust it to your needs.
Also, there're normal <tr></tr>
, <th></th>
and <td></td>
with attributes instead of <mat-cell></mat-cell>
etc.
Check out this page
https://material.angular.io/components/table/overview
Height of angular-material table not going below certain minimum height
You need to do:
.mat-row {
height: 25px;
}
Here you can see a stackblitz demo.
In Mat table Not able to specify height of the table and make the header as well as footer sticky
As i told earlier Scroll is coming on div because there is a table in that div as well as top-bottom paddding of (30+30) px in vertical direction as you can see in image below.
we can remove this problem by 2 solution
use margin instead of padding as we know margin are spaces outside any div not inside but in this situation it will work same as padding space.
.example-container {
height: 300px;
overflow: auto;
margin:30px
}
please look into image below for result of above code.
- second way to fix this problem is make another div outside
example-container
and add padding to that while overexample-container
will wrap the table. see the stackblitz code here
How to adjust angular mat-table header height ? The table I am working on has column groups(main header and sub headers)
Your problem is not with the <td>
elements but with the <tr>
ones.
just add this:
tr.mat-header-row{
height: 20px !important;
}
Set minimum number of rows on angular material table
I would do something like this:
ts
getData() {
this.service.getData().subscribe(r => {
const minLength = window.innerHeight / x; // x is your row height
if (!r) {
r = new Array(minLength);
} else {
if (r.length < minLength) {
r.push(...new Array(minLength - r.length))
}
}
this.dataSource.data = r;
});
}
Note: to use this I recommend you to use safe navigation operator:
https://angular.io/guide/template-syntax#safe-navigation-operator
If your API is always returning an array, and if there's no data it returns [], you can remove the first if else.
getData() {
this.service.getData().subscribe(r => {
const minLength = window.innerHeight / x; // x is your row height
if (r.length < minLength) {
r.push(...new Array(minLength - r.length))
}
this.dataSource.data = r;
});
}
Related Topics
How to Position Div Below Another Div
How to Make Multiple Divs Display in One Line But Still Retain Width
How to Center Text in Select Box
How to Keep Two Divs on the Same Line
Formatting Numbers (Decimal Places, Thousands Separators, Localization, etc) With CSS
How to Change Whole Page Background-Color in Angular
How to Fade the Edge of a Div With Just CSS
Split Div into 2 Columns Using CSS
Reduce Spacing Between Bootstrap Horizontal Form Controls
Canvas Is Stretched When Using CSS But Normal With "Width"/"Height" Properties
How to Combine :Nth-Child() or :Nth-Of-Type() With an Arbitrary Selector
Difference Between Display: Inline and Display: Inline-Block
How to Prevent Less from Trying to Compile CSS Calc() Properties
Difference Between Max-Device-Width and Max-Width For Mobile Web
Pure CSS to Make Font-Size Responsive Based on Dynamic Amount of Characters