gpt4 book ai didi

angular - PrimgNg : column sorting

转载 作者:行者123 更新时间:2023-12-03 18:41:12 25 4
gpt4 key购买 nike

我正在使用 <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>

最佳答案

替换

<th [pSortableColumn]="">
File Name
<p-sortIcon [field]=""></p-sortIcon>
</th>
使用
<th [pSortableColumn]="'sName'">
File Name
<p-sortIcon [field]=""></p-sortIcon>
</th>
例如,为了按名称排序。

关于angular - PrimgNg : <p-table> column sorting,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51082639/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com