我正在使用Primeng表,并试图使用列“重新排序”功能,但没有成功。
当我移动一列时,会显示“箭头”图像,但当我将该列放在其他位置时-什么也不会发生(该列仍然位于“前一个位置”)。
<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元素中使用p-table,在th元素上使用pReorderableColumn。我是不是遗漏了什么?
发布于 2018-07-03 10:57:39
我不断地将我的表与Primeng站点中的示例进行比较,发现我没有将cols数组绑定到p-table元素中的columns属性p-table。
<p-table
...
[columns]="cols"
>发布于 2019-06-09 03:24:43
今天有一个类似的问题,因为我想保存顺序和列的选择,所以我使用了<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));
}在那之后,对我来说一切都很顺利。希望它能帮助到某人:)
https://stackoverflow.com/questions/51150919
复制相似问题