Primeng: When sortOrder is specified in p-table, the sortField's sorting icon is not initially displayed

Created on 21 Sep 2018  路  2Comments  路  Source: primefaces/primeng

I'm submitting a ...

[x] bug report

Plunkr Case (Bug Reports)
https://stackblitz.com/edit/github-8bsq6q

Current behavior
When we specify a default sorting order for a p-table using sortOrder property, the default sorting icon is not displayed once the table loads. Although the data is sorted correctly and the column is highlighted properly, the sorting icon is not displayed to indicate the sortOrder (i.e. ascending or descending). If I click to reorder it, then it appears. Note that when sortOrder is NOT specified in the HTML, the icon appears correctly (sorted in ascending order which is the default).

Expected behavior
The sort-down or sort-up icons should be visible at first to indicate the default sort order, as specified.

Minimal reproduction of the problem with instructions
https://stackblitz.com/edit/github-8bsq6q

  • Angular version: 6.1.7

  • PrimeNG version: 6.1.3

  • Browser: Tested in Chrome, Firefox, Edge

  • Language: Typescript 2.9.2

  • Node (for AoT issues): node --version = 8.12.0

Most helpful comment

Hi,
Can you try this

<p-table sortField="name" [sortOrder]="-1">
  <ng-template pTemplate="header">
  <tr>
    <th [pSortableColumn]="'name'" pResizableColumn>Name<p-sortIcon [field]="'name'"></p-sortIcon>
    </th>
    <th [pSortableColumn]="'age'" pResizableColumn>Age<p-sortIcon [field]="'age'"></p-sortIcon>
    </th>
    <th [pSortableColumn]="'date'" pResizableColumn>Date<p-sortIcon [field]="'date'"></p-sortIcon>
    </th>
  </tr>
  </ng-template>
</p-table>

All 2 comments

Hi,
Can you try this

<p-table sortField="name" [sortOrder]="-1">
  <ng-template pTemplate="header">
  <tr>
    <th [pSortableColumn]="'name'" pResizableColumn>Name<p-sortIcon [field]="'name'"></p-sortIcon>
    </th>
    <th [pSortableColumn]="'age'" pResizableColumn>Age<p-sortIcon [field]="'age'"></p-sortIcon>
    </th>
    <th [pSortableColumn]="'date'" pResizableColumn>Date<p-sortIcon [field]="'date'"></p-sortIcon>
    </th>
  </tr>
  </ng-template>
</p-table>

Yes, this resolves the issue. I could never figure it out. Probably the documentation needs to be modified though.
Thanks Yigit!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

markgoho picture markgoho  路  3Comments

Faigjaz picture Faigjaz  路  3Comments

watalberto picture watalberto  路  3Comments

mitosandov picture mitosandov  路  3Comments

jisqaqov picture jisqaqov  路  3Comments