我使用 Angular Material Table,我需要一个命令按钮和表格页脚行中的表格分页器,像这样
我的代码实际上是这样的
<div class="example-table-container mat-elevation-z8">
<table mat-table [dataSource]="dataSource" multiTemplateDataRows>
<!-- DataSource's displayedColumns -->
<ng-container matColumnDef="{{column}}" *ngFor="let column of displayedColumns">
<th mat-header-cell *matHeaderCellDef> {{column}} </th>
<td mat-cell *matCellDef="let element"> {{element[column]}} </td>
</ng-container>
<!-- Exporter column -->
<ng-container matColumnDef="exporter">
<td mat-footer-cell *matFooterCellDef colspan="2">
<button class="btn btn-primary" (click)="exportCsv(dataSource)">
<i class="material-icons" title="Exporter en CSV">save_alt </i>
</button>
</td>
</ng-container>
<!-- Paginator column -->
<ng-container matColumnDef="paginator">
<td mat-footer-cell *matFooterCellDef colspan="3">
<mat-paginator [pageSizeOptions]="[5,10,20]" showFirstLastButtons></mat-paginator>
</td>
</ng-container>
<tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
<tr mat-row *matRowDef="let element; columns: displayedColumns;"></tr>
<tr mat-footer-row *matFooterRowDef="['exporter', 'paginator']"></tr>
</table>
</div>
如您所见,我将<mat-paginator>
元素移到了td
...但是这破坏了分页器,因为它不再对表格进行分页...(您会看到“ 0 of 0”并禁用分页按钮)...当我放它回到table
元素之外,分页器恢复正常......
如何正确地将分页器放在页脚行内?