Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PrimeNG Table get filtered row

I am using PrimeNG 6.0.2 with Angular 5 and I'm having issues with the Table plugin. I switched to Table because DataTable is deprecated. Now, I can't access filtered values the way I could before.

Let's say I define my table in component via ViewChild:

@ViewChild('myTable') dataTable: Table;

With DataTable, I could just access the _value property which held sorted and filtered data:

dataTable._value[index] = ...;

But now, this property hold just the sorted array, while I have to use the filteredValue property:

dataTable.filteredValue[index] = ...;

My problem with this is that the filteredValue is undefined before any filtering, has value when the table is filtered and is null after I remove all filter text. This yields some pretty ugly code.

Is it possible to access the current data, be it sorted, filtered or identical to the starting array? Or do I have to go with this approach?

like image 699
dzenesiz Avatar asked Aug 06 '18 14:08

dzenesiz


1 Answers

Another way you can access the filtered values is by declaring the onFilter event and then retrieve/store the filtered values.

// on your component class declare
onFilter(event, dt) { 
  this.filteredValues = event.filteredValue; 
}
<p-table #dt .... (onFilter)="onFilter($event, dt)">
like image 71
aquilesb Avatar answered Oct 13 '22 15:10

aquilesb