【发布时间】:2019-05-16 11:21:07
【问题描述】:
我正在使用 primeNg <p-table> 显示数据如下:
HTML
<p-table [value]="documents">
<ng-template pTemplate="header">
<tr>
<th [pSortableColumn]="'sName'">
File Name
<p-sortIcon [field]="'sName'"></p-sortIcon>
</th>
<th [pSortableColumn]="'sType'">
File Type
<p-sortIcon [field]="'sType'"></p-sortIcon>
</th>
<th [pSortableColumn]="sDate">
File Date
<p-sortIcon [field]="'sDate"></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-02-1999"
},
{
"sName":"Book",
"sType":"PDF",
"sDate":"09-10-2002"
},
{
"sName":"Cook Book",
"sType":"Text",
"sDate":"16-12-1989"
},
{
"sName":"Book",
"sType":"PDF",
"sDate":"25-04-2000"
},
{
"sName":"File",
"sType":"PDF",
"sDate":"02-01-1989"
}]
}
我的要求是 File Date 字段中的数据应该在页面加载时默认排序。请指导我如何在页面加载时按降序实现这个排序的File Date 列?排序按预期工作,但只有排序日期没有出现,请帮助我解决方法。
【问题讨论】:
-
为什么您的 sDate 值看起来不像日期?
标签: angular primeng primeng-datatable