6
votes

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?

2

2 Answers

5
votes

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)">
4
votes

I know this is quite a late answer but for anyone else having this problem, you can just use the table.hasFilter() function on the table itself and decide based on that which property to access. Results in quite some overhead as well but to me it feels a lot cleaner than doing !!table.filteredValue.