Hello,
I use the filtering of data table and i would like to retrieve the displayed data.
There is a way to retrieve or it was not implement ?
I watched the source code and I did not see any way to do it.
I also noticed that the csv export does not take into account the filtered data, which I find a bit strange.
Thanks
CSV export applying to filtered data would be a great feature. +1
You could make a change to primeng in node_modules. What happens on exportCSV function is that its using values instead of dataToRender. Technically all the fields of each object are identical at least from what I've seen. Not sure if there is any other diffs between them. Its just that DataToRender will accurately show the filtered items.
So in datatable.js under export CSV change this.values to:
this.dataToRender.forEach(function (record, i) {
csv += '\n';
for (var i_1 = 0; i_1 < _this.columns.length; i_1++) {
if (_this.columns[i_1].field) {
csv += _this.resolveFieldData(record, _this.columns[i_1].field);
if (i_1 < (_this.columns.length - 1)) {
csv += _this.csvSeparator;
}
}
}
});
Hi guys,
in primeng 2.0.4 it can be fixed easily next way:
...
public exportCSV() {
let data = this.filteredValue || this.value;
...
data.forEach((record, i) => {
...
@ajlviv, thanks. It works!. How can I get the filtered values to use it later?.
You can use onFilter event, something like that:
<p-dataTable #dt [value]="data" (onFilter)="onTableFiltered($event, dt.filteredValue)">
I do not know how many beers I owe you, @ajlviv.
You've saved my life, thanks!.
working....
Great! Thanks @ajlviv It works
I concur - thanks @ajlviv . Nice!
Okay, so if we've figured out how to do it, how come the devs have yet to bin this for release? @ajlviv maybe submit a PR with your changes?
Most helpful comment
You can use onFilter event, something like that:
<p-dataTable #dt [value]="data" (onFilter)="onTableFiltered($event, dt.filteredValue)">