If you get here for angular answer. There it is.
Put this code:
In html (adapt to your code):
<mat-header-row *matHeaderRowDef="getDisplayedColumns()"></mat-header-row>
<mat-row *matRowDef="let row; columns: getDisplayedColumns()"></mat-row>
<mat-footer-row *matFooterRowDef="getDisplayedColumns()"></mat-footer-row>
In the .ts
Make your class implements OnInit e OnDestroy
Declare these methods
isPortrait() {
return !this.landscape.matches;
}
handlerOrientation: any;
landscape = window.matchMedia("(orientation: landscape)");
ngOnDestroy(): void {
console.log('on destroy');
//https://stackoverflow.com/questions/46906763/how-to-remove-eventlisteners-in-angular-4
//https://code.daypilot.org/79036/angular-calendar-detect-orientation-change-landscape-portrait
this.landscape.removeEventListener("change", this.handlerOrientation, true);
}
private onChangeOrientation() {
console.log('landscape orientation');
}
landscape = window.matchMedia("(orientation: landscape)");
//https://stackoverflow.com/questions/47077302/angular2-material-table-hide-column
//https://stackoverflow.com/questions/41432533/how-to-detect-if-device-is-desktop-and-or-mobile-and-if-connection-is-wifi-or-n
getDisplayedColumns() : string[] {
let exibir = !this.isPortrait();
return this.displayedColumns.filter(cd => exibir || cd.showMobile).map(cd => cd.def);}
Declare the columns this way
displayedColumns = [{ def: 'data', showMobile: true}, { def: 'numero', showMobile: false}];
}
In OnInit put this
this.handlerOrientation = this.onChangeOrientation.bind(this);
this.landscape.addEventListener("change", this.handlerOrientation, true);