How to get sorted data from mat-table of all pages?

33 views Asked by At

I'm looking for a method to extract sorted data and save it under sortedData from dataSource of mat-table in order to save it to CSV file. There are filters and pagination applied to dataSource through

this.dataSource.filterPredicate; this.dataSource.paginator = this.paginator; this.dataSource.sort = this.sort

and I couldn't find any working solution except this

this.dataSource.connect().subscribe((data) => (this.sortedData = data))

but this solution returns data limited only to single page when applying MatPaginator and this

this.sortedData = this.dataSource.sortData(this.dataSource.data, this.dataSource.sort) 

which returns all data ignoring filtration.

Any ideas how could I get all sorted and filtered data (data of all pages) from dataSource?

1

There are 1 answers

1
Alpine A110R On

You can use filteredData :

The filtered set of data that has been matched by the filter string, or all the data if there is no filter.

const sortedData = this.dataSource.sortData(this.dataSource.filteredData, this.dataSource.sort)