<h1 class="mat-display-1">Subjects</h1>
<button mat-raised-button color="primary" (click)="openDialog()">Add</button>
<button mat-raised-button color="primary" (click)="delete()">Remove</button>
<br>
<mat-form-field appearance="fill">
  <mat-label>Filter</mat-label>
  <input matInput (keyup)="applyFilter($event)" #filter>
</mat-form-field>

<table *ngIf="subjectList" mat-table [dataSource]="subjectList" matSort>
  <ng-container matColumnDef="select">
    <th mat-header-cell *matHeaderCellDef>
      <mat-checkbox (change)="$event ? masterToggle() : null"
                    [checked]="selection.hasValue() && isAllSelected()"
                    [indeterminate]="selection.hasValue() && !isAllSelected()"
                    [aria-label]="checkboxLabel()">
      </mat-checkbox>
    </th>
    <td mat-cell *matCellDef="let row">
      <mat-checkbox (click)="$event.stopPropagation()"
                    (change)="$event ? selection.toggle(row) : null"
                    [checked]="selection.isSelected(row)"
                    [aria-label]="checkboxLabel(row)">
      </mat-checkbox>
    </td>
  </ng-container>

  <ng-container matColumnDef="no">
    <th mat-header-cell *matHeaderCellDef> No.</th>
    <td mat-cell *matCellDef="let subject"> {{subject.id}} </td>
  </ng-container>

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

  <ng-container matColumnDef="students">
    <th mat-header-cell *matHeaderCellDef> Students</th>
    <td mat-cell *matCellDef="let subject"> {{subject.studentsAssoc.length}} </td>
  </ng-container>

  <tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
  <tr mat-row *matRowDef="let row; columns: displayedColumns;" [routerLink]="[row.id]"></tr>
</table>

<mat-paginator [pageSizeOptions]="[5, 10, 20]"
               showFirstLastButtons
               aria-label="Select page">
</mat-paginator>
