p-table Sort Column Styling

UI Components for Angular
Post Reply
aejirbjorn
Posts: 6
Joined: 27 May 2021, 17:51

11 Jun 2021, 23:04

Hello,

I'd like to provide some visual distinction on a p-table to highlight the currently sorted column (the entire column, not just the header). Is there a property or some other means of determining which column is currently sorted so that a css class could be applied conditionally?

Thanks!

aejirbjorn
Posts: 6
Joined: 27 May 2021, 17:51

21 Jun 2021, 18:31

*Bump*...is there a means of determining which column a p-table is currently sorted on? I'd really like to be able to apply a style conditionally to the sorted column.

PhilHuhn
Posts: 177
Joined: 19 Sep 2018, 02:52
Location: Ann Arbor, Michigan USA
Contact:

23 Jun 2021, 21:06

Hey:
Yes!
I can think of two way of knowing what column is sorted.

1) use Lazy feature. On demand onLazyLoad method gets a LazyLoadEvent, which contains the single or multiple sort fields.

2) You can access the p-table component by ViewChild and get the change of sort with onSort event:

Code: Select all

<p-table #dt id='incidents-grid' [value]='incidents' (onSort)='onSort( )'
...

Code: Select all

import { Component, OnInit, OnDestroy, ViewChild, Input } from '@angular/core';
import { Table } from 'primeng/table';
...
  @ViewChild('dt', { static: true }) dt: Table | undefined;

  onSort( ) {
    if( this.dt ) {
      console.warn( this.dt.sortField );
    }
  }

PhilHuhn
Posts: 177
Joined: 19 Sep 2018, 02:52
Location: Ann Arbor, Michigan USA
Contact:

23 Jun 2021, 21:18

Hey, also check out the following...

Table Show list of active Filters
viewtopic.php?f=35&t=66932

Display of the filters in the footer via onLazyLoad event.

aejirbjorn
Posts: 6
Joined: 27 May 2021, 17:51

24 Jun 2021, 23:57

Thanks @PhilHun! That was exactly what I needed. Much appreciated.

Post Reply

Return to “PrimeNG”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 7 guests