gpt4 book ai didi

angular - Primeng Sortable Table 指定排序列

转载 作者:行者123 更新时间:2023-12-03 23:21:48 24 4
gpt4 key购买 nike

我有一个 PrimeNG 表,一切都按预期工作。我已经实现了排序。

我得到的是表中每一列的排序选项,但我只希望在特定列中使用此选项。

有什么建议吗?

提前谢谢

||威利..

<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>

最佳答案

从文档:

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

所以我想你想要的是检查 col.field是您想要排序的列。喜欢
[pSortableColumnDisabled]="col.field === 'whatever'"

另外,正如 Aman Chhabra 所提到的,在 p-sortIcon 上放一个 *ngIf
    <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>

关于angular - Primeng Sortable Table 指定排序列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51772701/

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