我有一张<p-table>桌子sortMode="multiple"。我想在页面首次显示时指定两列作为默认排序。如果我设置 sortMode="single",它可以通过指定 sortField="year" [sortOrder]="-1" 选项来工作(例如,标题显示为选中状态,列已排序)。多列相当于什么?
类似的示例代码(取自https://www.primefaces.org/primeng/showcase/#/table/sort)
<h3>Multi Sort with MetaKey</h3>
<p-table [columns]="cols" [value]="cars2" sortMode="multiple">
<ng-template pTemplate="header" let-columns>
<tr>
<th *ngFor="let col of columns" [pSortableColumn]="col.field">
{{col.header}}
<p-sortIcon [field]="col.field"></p-sortIcon>
</th>
</tr>
</ng-template>
<ng-template pTemplate="body" let-rowData let-columns="columns">
<tr>
<td *ngFor="let col of columns">
{{rowData[col.field]}}
</td>
</tr>
</ng-template>
</p-table>
Run Code Online (Sandbox Code Playgroud)
export class TableSortDemo implements OnInit {
cars1: Car[];
cars2: Car[];
cars3: Car[];
cols: any[];
constructor(private carService: CarService) { }
ngOnInit() {
this.carService.getCarsSmall().then(cars => this.cars1 = cars);
this.carService.getCarsSmall().then(cars => this.cars2 …Run Code Online (Sandbox Code Playgroud)