primeng,p-table 列 "reorder" 不工作
primeng, p-table column "reorder" is not working
我正在使用 Primeng table,并尝试使用列 "reorder" 功能,但没有成功。
当我移动一列时,会显示 "arrow" 图像,但是当我将列放在其他位置时 - 没有任何反应(该列仍在 "previous location" 中)。
<div class="container">
<p-table #dt [value]="pagedTasks"
[paginator]="true"
[rows]="pageSize"
[first]="first"
[lazy]="true"
[totalRecords]="totalRecords"
[autoLayout]="true"
(onLazyLoad)="loadTasksLazy($event)"
[responsive]="true"
sortField="id"
sortOrder="-1"
[reorderableColumns]="true"
>
<ng-template pTemplate="caption">
...
/ng-template>
<ng-template pTemplate="header">
<tr>
<th *ngFor="let col of cols" [pSortableColumn]="col.field" pReorderableColumn>
<div *ngIf="col.field !== 'actions'">
{{ col.header }}
<p-sortIcon [field]="col.field"></p-sortIcon>
</div>
<div *ngIf="col.field === 'actions'">
<fa name="file-code"></fa>
</div>
</th>
</tr>
...
</p-table>
</div>
如您所见,我在 p-table
元素中使用了 [reorderableColumns]="true"
,
和 pReorderableColumn
在 th
元素上。
我错过了什么吗?
我一直将我的 table 与 Primeng 站点中的示例进行比较,发现我没有将 cols 数组绑定到列 属性
[columns]="cols"
在 p-table
元素中。
<p-table
...
[columns]="cols"
>
今天遇到了类似的问题,因为我想保存顺序和列的选择,所以我使用了<p-table [columns]="selectedColumns" (onColReorder)="saveReorderedColumns($event)" ...>
问题是在我的函数中我没有再次设置 selectedColumns
。
解决方案是执行以下操作:
saveReorderedColumns(event: any) {
this.selectedColumns = this.clone(event.columns); // <-- important
localStorage.setItem(this.dataKeyForStorage, JSON.stringify(event.columns));
}
在那之后它对我来说工作正常。希望对某人有所帮助:-)
我正在使用 Primeng table,并尝试使用列 "reorder" 功能,但没有成功。
当我移动一列时,会显示 "arrow" 图像,但是当我将列放在其他位置时 - 没有任何反应(该列仍在 "previous location" 中)。
<div class="container">
<p-table #dt [value]="pagedTasks"
[paginator]="true"
[rows]="pageSize"
[first]="first"
[lazy]="true"
[totalRecords]="totalRecords"
[autoLayout]="true"
(onLazyLoad)="loadTasksLazy($event)"
[responsive]="true"
sortField="id"
sortOrder="-1"
[reorderableColumns]="true"
>
<ng-template pTemplate="caption">
...
/ng-template>
<ng-template pTemplate="header">
<tr>
<th *ngFor="let col of cols" [pSortableColumn]="col.field" pReorderableColumn>
<div *ngIf="col.field !== 'actions'">
{{ col.header }}
<p-sortIcon [field]="col.field"></p-sortIcon>
</div>
<div *ngIf="col.field === 'actions'">
<fa name="file-code"></fa>
</div>
</th>
</tr>
...
</p-table>
</div>
如您所见,我在 p-table
元素中使用了 [reorderableColumns]="true"
,
和 pReorderableColumn
在 th
元素上。
我错过了什么吗?
我一直将我的 table 与 Primeng 站点中的示例进行比较,发现我没有将 cols 数组绑定到列 属性
[columns]="cols"
在 p-table
元素中。
<p-table
...
[columns]="cols"
>
今天遇到了类似的问题,因为我想保存顺序和列的选择,所以我使用了<p-table [columns]="selectedColumns" (onColReorder)="saveReorderedColumns($event)" ...>
问题是在我的函数中我没有再次设置 selectedColumns
。
解决方案是执行以下操作:
saveReorderedColumns(event: any) {
this.selectedColumns = this.clone(event.columns); // <-- important
localStorage.setItem(this.dataKeyForStorage, JSON.stringify(event.columns));
}
在那之后它对我来说工作正常。希望对某人有所帮助:-)