我正在使用<p-table>,我必须实现对其头的排序。我所做的工作如下:
HTML
<p-table [value]="documents">
<ng-template pTemplate="header">
<tr>
<th [pSortableColumn]="">
File Name
<p-sortIcon [field]=""></p-sortIcon>
</th>
<th [pSortableColumn]="">
File Type
<p-sortIcon [field]=""></p-sortIcon>
</th>
<th [pSortableColumn]="">
File Date
<p-sortIcon [field]=""></p-sortIcon>
</th>
</tr>
</ng-template>
<ng-template pTemplate="body" let-doc>
<tr>
<td>
{{doc.sName}}
</td>
<td>
{{doc.sType}}
</td>
<td>
{{doc.sDate}}
</td>
</tr>
</ng-template>
</p-table>TS
ngOnInit(){
//made a service call and got data for
this.documents=[{
"sName":"Book",
"sType":"PDF",
"sDate":"20"
},
{
"sName":"Book",
"sType":"PDF",
"sDate":"20"
},
{
"sName":"Cook Book",
"sType":"Text",
"sDate":"20"
},
{
"sName":"Book",
"sType":"PDF",
"sDate":"25-04"
},
{
"sName":"File",
"sType":"PDF",
"sDate":"02-01"
}]
}我确实在我的代码中使用了[pSortableColumn]和[field],但是我没有得到传递给这个特定字段排序的值。数据正在正确地弹出--这只是我遗漏的排序。请指导我如何实现列的排序。谢谢
我不能使用<p-dataTable>
发布于 2018-06-28 12:41:48
替换
<th [pSortableColumn]="">
File Name
<p-sortIcon [field]=""></p-sortIcon>
</th>使用
<th [pSortableColumn]="'sName'">
File Name
<p-sortIcon [field]=""></p-sortIcon>
</th>例如,为了按sName进行排序。
发布于 2019-03-22 13:00:31
如果有人需要的话,只需在@Antikhippe接受的答案中添加更多的信息。
使用“接受答案”中的代码示例,p-排序图标不会更改。
因此,使用下面的代码是有效的。
<p-sortIcon [field]="'sName'"></p-sortIcon>https://stackoverflow.com/questions/51082639
复制相似问题