1

How can I sort multiple columns while using a p-table, PrimeNG | Angular UI Component Library?

<h3>Multi Sort Columns</h3>
<p-table
  [columns]="cols"
  [value]="cars1"
  [lazy]="lazy"
  [lazyLoadOnInit]="lazyLoadOnInit"
    (onLazyLoad)="loadList($event)"
  [sortMode]="sortMode"
  [multiSortMeta]="multiSortMeta">
    <ng-template pTemplate="header" let-columns>
        <tr>
            <th *ngFor="let col of columns" [pSortableColumn]="col.field">
                {{col.header}}
            </th>
        </tr>
    </ng-template>
    <ng-template pTemplate="body" let-rowData let-columns="columns">
        <tr>
            <td *ngFor="let col of columns">
                {{rowData[col.field]}}
            </td>
        </tr>
    </ng-template>
</p-table>

Can there be a default predefined secondary sort column ?

1
  • You haven't mentioned customSort() in <p-table> tag. How come you are able to call customSort() in typescript? AND did you find a way to set predefiend secondary sort. Because multiSortMeta sets the sorting just for first time... Commented Jan 31, 2024 at 2:13

1 Answer 1

2

Yes, you can define multiple predefined sorts by using multiSortMeta property.

Here is an example:

[multiSortMeta]="[{field: 'quantity', order: -1}, {field: 'price', order: 1}]"

See demo

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for the great answer, and demo as well.
In my case i want to set secondary sort predefined always, not just first time at the page load. multiSortMeta works only for once here.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.