PrimeNg:<p-table> 列排序

PrimgNg: <p-table> column sorting

我正在使用 <p-table>,我必须对其 headers 进行排序。我正在做如下:

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>

例如按 sName 排序。

如果有人需要,只需向@Antikhippe 接受的答案添加额外信息。

对于已接受答案中的代码示例,p 排序图标没有变化。

所以使用下面的代码是可行的。

<p-sortIcon [field]="'sName'"></p-sortIcon>