First of all I made a working example on stackblitz:
Stackblitz-Example
I basically made the following changes to bring select
and name
in the same column:
The modified part of the TS-File:
displayedColumns: string[] = ['selectAndName', 'position', 'weight', 'symbol'];
The modified part of the HTML-File:
<ng-container matColumnDef="selectAndName">
<th mat-header-cell *matHeaderCellDef>
<mat-checkbox
(change)="$event ? masterToggle() : null"
[checked]="selection.hasValue() && isAllSelected()"
[indeterminate]="selection.hasValue() && !isAllSelected()"
>
</mat-checkbox>
Select and name
</th>
<td mat-cell *matCellDef="let element">
<mat-checkbox
(click)="$event.stopPropagation()"
(change)="$event ? selection.toggle(element) : null"
[checked]="selection.isSelected(element)"
>
</mat-checkbox>
{{element.name}}
</td>
</ng-container>