Primeng Sortable Table specify Sorted Column

人盡茶涼 提交于 2019-12-11 08:14:02

问题


i have a PrimeNG Table everything woks as expected. I have implemented sorting.

What i get is the sort Option for every Column in the Table but i want this option only in a specific Column.

Any Advice ?

Thx in Advance

|| Willi ..

<p-table [columns]="wikiCols" [value]="wikiItems" selectionMode="single" [(selection)]="selectedItem">
  <ng-template pTemplate="header">
    <tr>
      <th *ngFor="let col of wikiCols" [pSortableColumn]="col.field" >
        {{col.header}}
        <p-sortIcon [field]="col.field" ariaLabel="Activate to sort" ariaLabelDesc="Activate to sort in descending order" ariaLabelAsc="Activate to sort in ascending order"></p-sortIcon>
      </th>
    </tr>
  </ng-template>
  <ng-template pTemplate="body" let-rowData let-columns="columns">
    <tr [pSelectableRow]="rowData">
    <td *ngFor="let col of wikiCols">
      {{rowData[col.field]}}
    </td>
    </tr>
  </ng-template>
</p-table>

回答1:


From the docs:

A column can be made sortable by adding the pSortableColumn directive whose value is the field to sort against and a sort indicator via p-sortIcon component. For dynamic columns, setting pSortableColumnDisabled property as true disables sorting for that particular column.

https://www.primefaces.org/primeng/#/table

So I think what you want, is to check if the col.field is the column you want to be sortable. Like

[pSortableColumnDisabled]="col.field === 'whatever'"

Also, as mentioned by Aman Chhabra, put an *ngIf on p-sortIcon

    <p-sortIcon *ngIf="col.field !== 'whatever'" [field]="col.field" ariaLabel="Activate to sort" ariaLabelDesc="Activate to sort in descending order" ariaLabelAsc="Activate to sort in ascending order"></p-sortIcon>


来源:https://stackoverflow.com/questions/51772701/primeng-sortable-table-specify-sorted-column

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!