3

I would like your help to identify the reason for the select option does not appear in angular 6 mat-paginator. And how to set style for Back button and Next Button.

I'm trying follow the example below:

https://stackblitz.com/angular/anvplbamrbj?file=app%2Ftable-pagination-example.html

In example above when I click on mat-option from mat-paginator the select option appear over the table. When I copy this example for my project the select option from mat-paginator appear below the table. I don't know why does it happen.

follow the printout of the problem here

As we can see in print sreen, the mat-paginator is working, but when I click on "itens per page" options" The select option appear invisible (I only can see the select option when I inspect element from web page.

So I think that this problem is in some CSS file, but I don't know how to fix it?

follow my code below:

list-devices.component.html: I only copy and past the example from stackblitz.com

<div class="mat-elevation-z8">
  <table mat-table [dataSource]="dataSource">
   <!-- Position Column -->
   <ng-container matColumnDef="position">
     <th mat-header-cell *matHeaderCellDef> No. </th>
     <td mat-cell *matCellDef="let element"> {{element.position}} </td>
   </ng-container>

   <!-- Name Column -->
   <ng-container matColumnDef="name">
     <th mat-header-cell *matHeaderCellDef> Name </th>
     <td mat-cell *matCellDef="let element"> {{element.name}} </td>
   </ng-container>

   <!-- Weight Column -->
   <ng-container matColumnDef="weight">
     <th mat-header-cell *matHeaderCellDef> Weight </th>
     <td mat-cell *matCellDef="let element"> {{element.weight}} </td>
   </ng-container>

   <!-- Symbol Column -->
   <ng-container matColumnDef="symbol">
     <th mat-header-cell *matHeaderCellDef> Symbol </th>
     <td mat-cell *matCellDef="let element"> {{element.symbol}} </td>
   </ng-container>

   <tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
   <tr mat-row *matRowDef="let row; columns: displayedColumns;"></tr>
  </table>

  <mat-paginator [pageSizeOptions]="[5, 10, 20]" showFirstLastButtons></mat-paginator>
</div>

.ts file

 import { Component, OnInit, ViewChild} from '@angular/core';
 import {MatPaginator, MatTableDataSource} from '@angular/material';

 /**
  * Controller for list devices view
  *
  * @export
  * @class ListDevicesComponent
  * @implements {OnInit}
 */
 @Component({
    selector: 'app-list-device-home',
    templateUrl: './list-devices.component.html',
    styleUrls: ['./list-devices.component.scss']
 })
 export class ListDevicesComponent implements OnInit {
   displayedColumns: string[] = ['position', 'name', 'weight', 'symbol'];
   dataSource = new MatTableDataSource<PeriodicElement>(ELEMENT_DATA);

   @ViewChild(MatPaginator) paginator: MatPaginator; 

   ngOnInit() {
     this.dataSource.paginator = this.paginator;
   }
 }


 export interface PeriodicElement {
   name: string;
   position: number;
   weight: number;
   symbol: string;
 }

 const ELEMENT_DATA: PeriodicElement[] = [
    {position: 1, name: 'Hydrogen', weight: 1.0079, symbol: 'H'},
    {position: 2, name: 'Helium', weight: 4.0026, symbol: 'He'},
    {position: 3, name: 'Lithium', weight: 6.941, symbol: 'Li'},
    {position: 4, name: 'Beryllium', weight: 9.0122, symbol: 'Be'},
    {position: 5, name: 'Boron', weight: 10.811, symbol: 'B'},
    {position: 6, name: 'Carbon', weight: 12.0107, symbol: 'C'},
    {position: 7, name: 'Nitrogen', weight: 14.0067, symbol: 'N'},
    {position: 8, name: 'Oxygen', weight: 15.9994, symbol: 'O'},
    {position: 9, name: 'Fluorine', weight: 18.9984, symbol: 'F'},
    {position: 10, name: 'Neon', weight: 20.1797, symbol: 'Ne'},
    {position: 11, name: 'Sodium', weight: 22.9897, symbol: 'Na'},
    {position: 12, name: 'Magnesium', weight: 24.305, symbol: 'Mg'},
    {position: 13, name: 'Aluminum', weight: 26.9815, symbol: 'Al'},
    {position: 14, name: 'Silicon', weight: 28.0855, symbol: 'Si'},
    {position: 15, name: 'Phosphorus', weight: 30.9738, symbol: 'P'},
    {position: 16, name: 'Sulfur', weight: 32.065, symbol: 'S'},
    {position: 17, name: 'Chlorine', weight: 35.453, symbol: 'Cl'},
    {position: 18, name: 'Argon', weight: 39.948, symbol: 'Ar'},
    {position: 19, name: 'Potassium', weight: 39.0983, symbol: 'K'},
    {position: 20, name: 'Calcium', weight: 40.078, symbol: 'Ca'},
  ];

list-devices.component.scss

@import '~@angular/material/prebuilt-themes/deeppurple-amber.css';

.label{
  border-radius: 4px;
  font-size: 75%;
  padding: 4px 7px;
  margin-right: 5px;
  font-weight: 400;
  color: #fff !important;
}

.mat-paginator-navigation-first {
  background: #11c15b;
}

.label-success{
  border-radius: 4px;
  font-size: 75%;
  padding: 4px 7px;
  margin-right: 5px;
  font-weight: 400;
  color: #fff !important;
  background: #11c15b;
}

.label-warning{
  border-radius: 4px;
  font-size: 75%;
  padding: 4px 7px;
  margin-right: 5px;
  font-weight: 400;
  color: #fff !important;
  background: #e5e500;
}

.label-danger{
  border-radius: 4px;
  font-size: 75%;
  padding: 4px 7px;
  margin-right: 5px;
  font-weight: 400;
  color: #fff !important;
  background: #ff5252;
}

.roow {
  display: flex;
  overflow-x: scroll;
}

.mat-table {
  width: 100%;
}

.td-style {
  font-family: "Roboto", sans-serif;
  font-size: 1.1em;
  color: #455a64;
}

 .th-style {
   font-family: "Roboto", sans-serif;
   font-size: 1em;
   font-weight: bold;
   color: #455a64; 
 }

.table-title-style {
  margin: 20px;
  margin-top: 5px;
  margin-bottom: 0px;
  color: #37474f;
  font-weight: 500;
  position: relative;
  position: sticky;
  font-size: 15px;
  top: 0;
 }

 .mat-header-row {
   position: sticky;
   top: 0;
   background-color: #fff;
 }

.body { 
  font-family: Roboto, Arial, sans-serif;
  margin: 0;
}

.basic-container {
  padding: 30px;
}

.version-info {
  font-size: 8pt;
  float: right;
 }

 /** No CSS for this example */
 ::ng-deep .mat-select-content{
    background-color: red;
    font-size: 1.5em;
 }

 table {
   width: 100%;
 }
Groben
  • 1,374
  • 2
  • 10
  • 29
Joh
  • 171
  • 3
  • 17
  • Can you create a stackblitz or anything reproducing your issue? I can think of a missing import or something like that but maybe I'm not seeing it; you installed Angular Material as well? – IvanS95 Nov 05 '18 at 16:08
  • 1
    Hello Ivan, thank you for you comment. follow the link from stackblitz reproducing the error: https://stackblitz.com/edit/angular-p3tm7y – Joh Nov 05 '18 at 16:47
  • Okay, I'm seeing something, it seems you haven't included the BrowsersAnimationModule.. can you try this and give an update? https://material.angular.io/guide/getting-started#step-2-configure-animations – IvanS95 Nov 05 '18 at 16:50
  • Hey Ivan, but I import this module: import { BrowserMo?dule } from '@angular/platform-browser'; this one it's not the same? – Joh Nov 05 '18 at 17:01
  • No, you actually need both, but right now I tried something else and imported a theme in `styles.css` and it worked just fine – IvanS95 Nov 05 '18 at 17:02
  • Could you please share with me your style.css? – Joh Nov 05 '18 at 17:04
  • `@import '~@angular/material/prebuilt-themes/deeppurple-amber.css';` just add this single line to `styles.css` – IvanS95 Nov 05 '18 at 17:05

1 Answers1

2

Remember to follow the documentation to install Angular Material correctly as shown here: https://material.angular.io/guide/getting-started

For your question, it seems that you didn't include the BrowsersAnimationModule which affects the animation of the modal boxes that contains the options for the select, also, you need to import the theme in the styles.css file for it to apply globally, this will ensure that all the styles from Angular Material are available in your application.

styles.css

/* Add application styles & imports to this file! */
@import '~@angular/material/prebuilt-themes/deeppurple-amber.css';
IvanS95
  • 5,364
  • 4
  • 24
  • 62