Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular 6 Get sorted data from Material Table

Is there any way to get the sorted data from a material table after sorts on the table have been applied? I can see "filteredData" in the table datasource but there's no "sortedData". The reason why I want the sorted data is so that I can export it in a csv file while maintaining all of the sorts applied. I've been using the built in MatSort to sort individual columns in the table.

like image 862
SomebodyOnEarth Avatar asked Jul 26 '18 18:07

SomebodyOnEarth


People also ask

What is matSortDisableClear?

What is matSortDisableClear? matSortDirection: The sort direction of the currently active MatSortable. matSortDisableClear: Whether to disable the user from clearing the sort by finishing the sort direction cycle.

What is MatTableDataSource?

MatTableDataSource. Data source that accepts a client-side data array and includes native support of filtering, sorting (using MatSort), and pagination (using MatPaginator). Allows for sort customization by overriding sortingDataAccessor, which defines how data properties are accessed.


1 Answers

There is a sort data method, that you can use with either datasource.data or datasource.filteredData

    dataSource.sortData(dataSource.filteredData,dataSource.sort);
like image 65
BenL Avatar answered Sep 28 '22 06:09

BenL