Wrap Your Data Source in a MatTableDataSource: If you do not wrap your own datasource--probably an array--in the MatTableDataSource class you'll have to write your own sorting algorithm to affect your data because it won't work out of the box.

this.rowData = new MatTableDataSource(myRowDataArray);

Do this because it makes your life easier.

Tell the data source about your sort: Your MatTableDataSource does not know about the sort by default. Get a ViewChild instance to the sort in your code:

@ViewChild(MatSort) sort: MatSort;

And apply that:

ngOnInit() { this.rowData.sort = this.sort;}

Hopefully you got this far and your table is sorting now.

Write Your Own Sort: If you're avoiding using the MatTableDataSource for some reason, you'll have to write your own sort algorithm. In the HTML, listen for the matSortChange event: