我已经使用PrimeNG Table创建了一个Angular应用程序。我已经在此处(https://www.primefaces.org/primeng/#/table/sort)检查了PrimeNG文档。问题是我的表没有排序。正在显示排序图标,当我按其中任何一个时,动画都会发生变化,但是数据没有被排序。
这是我的组件代码。
import { Component, OnDestroy, OnInit } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { DownloadService } from '../services/download/download.service';
import { SelectItem, MultiSelectModule } from "primeng/primeng";
@Component({
selector: 'app-downloads',
templateUrl: './downloads.component.html',
styleUrls: ['./downloads.component.css'],
providers: [DownloadService]
})
export class DownloadsComponent implements OnInit {
downloadData: any[] = [];
cols: any[];
columnOptions: SelectItem[];
constructor(private http: HttpClient, private data: DownloadService) { }
ngOnInit() {
this.getData();
setInterval(() => {
this.getData();
}, 5000);
}
getData() {
this.data.GetDownloads().subscribe(data => {
this.downloadData = data;
});
}
}
以及component.html的代码
<p-table [value]="downloadData" [rows]="10" [paginator]="true" sortMode="multiple" [rowsPerPageOptions]="[5,10,20]" [rowHover]="true">
<ng-template pTemplate="header">
<tr>
<th style="text-align: center;" [pSortableColumn]="'Logger Name'">Logger Name
<p-sortIcon [field]="'Logger Name'"></p-sortIcon>
</th>
<th style="text-align: center;" [pSortableColumn]="'Progress'">Progress
<p-sortIcon [field]="'Progress'"></p-sortIcon>
</th>
</tr>
</ng-template>
<ng-template pTemplate="body" let-download>
<tr>
<td style="text-align: center;">{{ download.logger.name }}</td>
<td style="text-align: center;">
<p-progressBar [value]="download.progress"></p-progressBar>
</td>
</tr>
</ng-template>
</p-table>
答案 0 :(得分:0)
显然,我在p-table标记中缺少#dt [columns] =“ cols”指令。填充cols字段并添加指令可以解决该问题。