简体   繁体   English

primeng,p表列“重新排序”不起作用

[英]primeng, p-table column “reorder” is not working

i am using Primeng table , and trying to use column "reorder" feature, without success. 我正在使用Primeng表 ,并尝试使用列“重新排序”功能,但未成功。

When i am moving a column, the "arrow" image is shown, but when i am dropping the column in other location - nothing happen(the column is still in the "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>

As you can see, i am using [reorderableColumns]="true" in p-table element, and pReorderableColumn on th element. 如您所见,我在p-table元素中使用[reorderableColumns]="true" ,在th元素中使用pReorderableColumn Am I missing something? 我想念什么吗?

I kept comparing my table to the example in Primeng site, and found that i didn't bind the cols array to the columns property [columns]="cols" in the p-table element. 我一直将表与Primeng网站中的示例进行比较,发现我没有将cols数组绑定到p-table元素中的column属性[columns]="cols"

<p-table
...
[columns]="cols"
>

Had a similar issue today, since i want to save the order and the selection of the columns, i used <p-table [columns]="selectedColumns" (onColReorder)="saveReorderedColumns($event)" ...> 今天有一个类似的问题,因为我想保存顺序和列的选择,所以我使用了<p-table [columns]="selectedColumns" (onColReorder)="saveReorderedColumns($event)" ...>

Problem was that in my function i did not set the selectedColumns again. 问题是在我的函数中,我没有再次设置selectedColumns Solution was doing the following: 解决方案正在执行以下操作:

saveReorderedColumns(event: any) {
  this.selectedColumns = this.clone(event.columns); // <-- important
  localStorage.setItem(this.dataKeyForStorage, JSON.stringify(event.columns));
}

after that it was working fine for me. 之后,它对我来说很好。 Hope it helps someone :-) 希望它可以帮助某人:-)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM