From a43874084f0a70e8a5ffb329a64d0245a5c34115 Mon Sep 17 00:00:00 2001 From: HermanWKeuris Date: Wed, 10 Jul 2024 08:54:52 +0200 Subject: [PATCH 1/2] docs(material/table): describe how to properly update MatTableDataSource Added a description of how to update MatTableDataSource without breaking sorting Fixes #27708 --- src/material/table/table.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/material/table/table.md b/src/material/table/table.md index 778e32cb806f..b181b637da59 100644 --- a/src/material/table/table.md +++ b/src/material/table/table.md @@ -200,6 +200,8 @@ Note that if the data properties do not match the column names, or if a more com accessor is required, then a custom `sortingDataAccessor` function can be set to override the default data accessor on the `MatTableDataSource`. +When updating the data soure asynchronously avoid doing so by reinstanciate the entire `MatTableDataSource` as this could break sorting. Rather update it through the `MatTableDataSource.data` property. + If you are not using the `MatTableDataSource`, but instead implementing custom logic to sort your data, listen to the sort's `(matSortChange)` event and re-order your data according to the sort state. If you are providing a data array directly to the table, don't forget to call `renderRows()` on the From 4d5b09516da23e9595b70fffee8068650d75e5ea Mon Sep 17 00:00:00 2001 From: HermanWKeuris Date: Thu, 11 Jul 2024 12:39:16 +0200 Subject: [PATCH 2/2] Updated copy from reinstanciate to recreating --- src/material/table/table.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/material/table/table.md b/src/material/table/table.md index b181b637da59..a322884382d7 100644 --- a/src/material/table/table.md +++ b/src/material/table/table.md @@ -200,7 +200,7 @@ Note that if the data properties do not match the column names, or if a more com accessor is required, then a custom `sortingDataAccessor` function can be set to override the default data accessor on the `MatTableDataSource`. -When updating the data soure asynchronously avoid doing so by reinstanciate the entire `MatTableDataSource` as this could break sorting. Rather update it through the `MatTableDataSource.data` property. +When updating the data soure asynchronously avoid doing so by recreating the entire `MatTableDataSource` as this could break sorting. Rather update it through the `MatTableDataSource.data` property. If you are not using the `MatTableDataSource`, but instead implementing custom logic to sort your data, listen to the sort's `(matSortChange)` event and re-order your data according to the sort state.