Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

primeng, p-table column "reorder" is not working

i am using Primeng table, and trying to use column "reorder" feature, without success.

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. Am I missing something?

like image 834
E.Meir Avatar asked Oct 16 '25 22:10

E.Meir


2 Answers

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.

<p-table
...
[columns]="cols"
>
like image 120
E.Meir Avatar answered Oct 18 '25 15:10

E.Meir


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)" ...>

Problem was that in my function i did not set the selectedColumns again. 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 :-)

like image 30
djnose Avatar answered Oct 18 '25 15:10

djnose



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!