Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular 2 Material Design Responsive Tables

Whenever I squeeze my window size, the table cell data overlaps with other cell's data and they are no longer aligned with my header. What should I do to make it responsive? I have already tried overflow-x:auto, is there anything which make my table horizontally scrollable. If not then any solution for stacked view table for smaller screens it will also work for me as well.

<div fxLayout="column" fxFlex="80" class="scrollable-table"  >

  <ng-container>

    <md-table class="mat-body-1 responsive-table" #table [dataSource]="viewModelSource">        
      <ng-container mdColumnDef="id" style="margin-right:200px;">
        <md-header-cell *mdHeaderCellDef class="ngBold"> ID </md-header-cell>
        <md-cell *mdCellDef="let row" routerLink="{{__PAGE_ROUTE}}{{row.id}}">
          {{row.id}}<br/>
        </md-cell>
      </ng-container>
      <ng-container mdColumnDef="sapCode">
        <md-header-cell *mdHeaderCellDef class="ngBold"> Sap Code </md-header-cell>
        <md-cell *mdCellDef="let row"> {{row.sapCode}} </md-cell>
      </ng-container>
      <ng-container mdColumnDef="divisionName">
        <md-header-cell *mdHeaderCellDef class="ngBold"> Division </md-header-cell>
        <md-cell *mdCellDef="let row">{{row.divisionName}} </md-cell>
      </ng-container>
      <ng-container mdColumnDef="faxNo">
        <md-header-cell *mdHeaderCellDef class="ngBold"> Fax </md-header-cell>
        <md-cell *mdCellDef="let row"> {{row.faxNo}} </md-cell>
      </ng-container>
      <ng-container mdColumnDef="gst">
        <md-header-cell *mdHeaderCellDef class="ngBold"> GST </md-header-cell>
        <md-cell *mdCellDef="let row"> {{row.gst}} </md-cell>
      </ng-container>

      <ng-container mdColumnDef="ntnNo">
        <md-header-cell *mdHeaderCellDef class="ngBold"> NTN </md-header-cell>
        <md-cell *mdCellDef="let row"> {{row.ntnNo}} </md-cell>
      </ng-container>
      <ng-container mdColumnDef="phoneNo">
        <md-header-cell *mdHeaderCellDef class="ngBold"> Phone No </md-header-cell>
        <md-cell *mdCellDef="let row"> {{row.phoneNo}} </md-cell>
      </ng-container>
      <ng-container mdColumnDef="shortName">
        <md-header-cell *mdHeaderCellDef class="ngBold"> Short Name </md-header-cell>
        <md-cell *mdCellDef="let row"> {{row.shortName}} </md-cell>
      </ng-container>
      <ng-container mdColumnDef="title">
        <md-header-cell *mdHeaderCellDef class="ngBold"> Title </md-header-cell>
        <md-cell *mdCellDef="let row"> {{row.title}} </md-cell>
      </ng-container>
      <ng-container mdColumnDef="website">
        <md-header-cell *mdHeaderCellDef class="ngBold"> Website </md-header-cell>
        <md-cell *mdCellDef="let row"> {{row.website}} </md-cell>
      </ng-container>
      <ng-container mdColumnDef="address">
        <md-header-cell *mdHeaderCellDef class="ngBold"> Address </md-header-cell>
        <md-cell *mdCellDef="let row"> {{row.address}} </md-cell>
      </ng-container>          
      <md-header-row *mdHeaderRowDef="displayedColumns" class="ngBackground"></md-header-row>
      <md-row *mdRowDef="let row; columns: displayedColumns;"></md-row>
    </md-table>

  </ng-container>
</div>
like image 804
arkhan Avatar asked Oct 07 '17 17:10

arkhan


1 Answers

from : https://github.com/angular/material2/issues/8680#issuecomment-348273320

(I added https://github.com/angular/material2/issues/8680#issuecomment-358187897)

I ended up making my own modifications :

.mat-row, .mat-header-row {
  width: 450vw; //PERSONALLY I HAD 45 COLUMNS
}
.mat-header-row { //THIS MAKES THE HEADER STICKY
  position: sticky;
  position: -webkit-sticky;
  top: 0;
  z-index: 1;
  background-color: inherit;
}
.table { //OR WHATEVER YOU CALL THE mat-table
  overflow: scroll;
}

tell me if this suits you.

like image 54
tatsu Avatar answered Nov 15 '22 04:11

tatsu