Skip to content

Instantly share code, notes, and snippets.

@jbaranski
Last active July 12, 2020 02:26
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jbaranski/3ce6581b05f0a360e4e9df836038d177 to your computer and use it in GitHub Desktop.
Save jbaranski/3ce6581b05f0a360e4e9df836038d177 to your computer and use it in GitHub Desktop.
Multi table angular sort
// assume you have a member on the component like dataSource1: MatTableDataSource<any>; and dataSource2: MatTableDataSource<any>; that
// are the datasources for the two tables
@ViewChildren(MatSort) set matSort(matSortList: QueryList<MatSort>) {
const ref = this;
matSortList.forEach((matSort: any, index: number) => {
const dataSource = ref['dataSource' + (index + 1)];
// https://material.angular.io/components/table/api
// to see about sortingDataAccessor
dataSource.sortingDataAccessor = (item: any, property: string) => {
if (cond1) {
return 'something?'
} else {
return 'something else?'
}
};
dataSource.sort = matSort;
});
}
@Thakrerhl
Copy link

But how to manage at html side, I have created dynamic sort at component, bit i am facing problem while applying it to tables.

@jbaranski
Copy link
Author

This was a comment code example in relation to this answer, where the markup is: https://stackoverflow.com/a/49056060/786467

You should be able to piece things together from there.

@Thakrerhl
Copy link

Thakrerhl commented May 1, 2020 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment