Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

PrimeNG Table Sorting – Only show icons when sorted

I have a pretty standard PrimeNG table that has sortable columns. But by default, the sort icons appear. Is it possible to only show the sort icons when the column has been sorted?

<p-table [value]="rows" styleClass="p-datatable-striped"   responsiveLayout="scroll">
<ng-template pTemplate="header">
    <tr>
        <th pSortableColumn="id">ID<p-sortIcon field="id"></p-sortIcon></th>
        <th pSortableColumn="name">Study Name<p-sortIcon field="name"></p-sortIcon></th>
        <th pSortableColumn="status">Status<p-sortIcon field="status"></p-sortIcon></th>
        <th pSortableColumn="createdOn">Created Date<p-sortIcon field="createdOn"></p-sortIcon></th>
        <th pSortableColumn="updatedOn">Last Updated Date<p-sortIcon field="updatedOn"></p-sortIcon></th>
    </tr>
</ng-template>
<ng-template pTemplate="body" let-row>
    <tr>
        <td>{{row.id}}</td>
        <td>{{row.name}}</td>
        <td>{{row.status}}</td>
        <td>{{row.createdOn | date : 'MM/dd/yyyy'}}</td>
        <td>{{row.updatedOn | date : 'MM/dd/yyyy'}}</td>
    </tr>
</ng-template>

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

You can use this css. It will hide the sort when it is not applied on a column!

.ui-sortable-column-icon.pi.pi-fw.pi-sort {
  visibility: hidden;
}

forked stackblitz

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading