Last active
July 12, 2020 02:26
-
-
Save jbaranski/3ce6581b05f0a360e4e9df836038d177 to your computer and use it in GitHub Desktop.
Multi table angular sort
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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; | |
}); | |
} |
Thanks for your quick response sir,
I tried that approach you suggested, but that one is static where they
defining mat sort statically on each table.
But in my situation there are multiple tables, somehow i managed to write
code for sorting at components but I don't know how to apply it to the
tables.
…On Fri, 1 May, 2020, 05:06 Jeff Baranski, ***@***.***> wrote:
***@***.**** commented on this gist.
------------------------------
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.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<https://gist.github.com/3ce6581b05f0a360e4e9df836038d177#gistcomment-3277293>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ANPVLRQLA4WJ52PSJNQ6JFLRPIDPLANCNFSM4MWADQHA>
.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.