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!
p-table Sort Column Styling
-
- Posts: 6
- Joined: 27 May 2021, 17:51
*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.
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:
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 );
}
}
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.
Table Show list of active Filters
viewtopic.php?f=35&t=66932
Display of the filters in the footer via onLazyLoad event.
-
- Posts: 6
- Joined: 27 May 2021, 17:51
Thanks @PhilHun! That was exactly what I needed. Much appreciated.
-
- Information
-
Who is online
Users browsing this forum: No registered users and 7 guests