7

I am using Angular Material Data table in my application. I need to display multiple columns with a horizontal scroll table. I am facing an issue with the table row border. It's not displaying an entire width of the row. Please check the attached image for your reference. Please help me to resolve this issue.

Please check the Link for Code reference

https://stackblitz.com/edit/angular-mdxik6?file=app%2Ftable-basic-example.html

enter image description here

Thanks in Advance.

4
  • Please post your code. It is not possible to debug a problem with just a screen capture. Commented Mar 13, 2018 at 20:14
  • Added link above. Please check. Help me on this Commented Mar 13, 2018 at 20:53
  • It is related to your table and row max-width settings and your cell min-width settings. I hope that helps. I'm not able to dig any deeper right now. Commented Mar 13, 2018 at 21:32
  • you will find workable example here. [stackoverflow.com/questions/50824617/… Commented Nov 20, 2019 at 15:24

9 Answers 9

3

Both header row and column rows are display flex by default, changing it to display inline-flex will fix above issue

.mat-header-row, .mat-row {
    display: inline-flex;
}
Sign up to request clarification or add additional context in comments.

2 Comments

please refer link below for more details css-tricks.com/snippets/css/a-guide-to-flexbox
I have to add min-width: 100%; otherwise the columns are misaligned
1

Use display grid in case of ipad and mobile device screens

mat-table {
   display: -ms-grid ;
   display: grid;
}

Comments

1

This might help someone else as this is an old post. Please refer to https://stackblitz.com/edit/angular-mdxik6-gnpzuh?embed=1&file=app/table-basic-example.css

Just add the following to your your-comp-component.css or your-comp-component.scss

.mat-row, .mat-header-row {
min-width: 2800px;
width: 100%;
}

Comments

1

Best resolve I did overcome this problem.

  1. Hold dynamic data column with css

    columns = [
            {columnDef: 'select', width: 75},
            ...........
    ]
    
  2. Recalculate css min width if you implement a show/hide function

    recalculateCss() {
        let cellWidth = 0;
        for (let i = 0; i < this.selected.length; i++) {
            const cell = this.selected[i];
            const column = this.columns.filter((value, index) => value.columnDef === cell);
            cellWidth += column[0] ? column[0].width : 0;
        }
        this.minWidth = cellWidth;
    }
    
  3. Add css in both mat-header-row and mat-row

    [style.min-width.px]="minWidth"
    

Comments

0

You have style properties that are working against each other. You've set min-width: 150px; for each column, and you have 13 columns which totals 1950px. Plus you've set width: 1123px; on each row which is (obviously) less than 1950px. Also, you set max-width: 1123px; - same width as your rows - on the table itself, but the table needs to be wider than the row in order to show the scrollbar. If you fix those problems, the border will display properly. Try setting just your row width and leaving out the table and column widths settings.

Comments

0

Material uses a flex layout so you could add align-self: stretch; to the columns CSS. This should stretch the auto-sized items to fit the table.

Edit

Stackblitz

Removing your header and cell width element helps. You want to set your rows to have a 100% width then set a desired minimum.

.mat-row, .mat-header-row { min-width: 1123px; width:100%; }

3 Comments

Please add some of your CSS.
Added link above. Please check. Help me on this
Updated answer.
0

Guys this is will help you solving such issues

You have to start using :

width: max-content;

.mat-row,
.mat-header-row {
  min-width: 1123px;
  width: 100%;
  width: max-content;
}

.mat-table {
  overflow: scroll;
  max-height: 500px;
}

.mat-cell,
.mat-header-cell {
  min-width: 90px;
}
/*unnecessary to make table header fixed*/
.mat-header-row {
  top: 0;
  position: sticky;
  z-index: 1;
  background-color: inherit;
  text-align: center;
}

find browsers support : https://caniuse.com/#search=fit-content

Comments

0

You need to set the expected with of the table in mat-table{min-width} plus the mat-row left and right paddings (24px each).

In your example case:

.mat-table {
  min-width: calc((13 * 150px) + 48px);
}

or

.mat-table {
  min-width: 1998px;
}

Hope this helps!!!

Comments

0

Try to use below styling. It helps to render data & borders correctly when more columns in mat-table. (horizontal scrolling issue resolved)

.mat-header-cell{
    background-color: inherit;
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.