@@ -151,7 +151,32 @@ export class _MatTableDataSource<
151151 * @param data Data object that is being accessed.
152152 * @param sortHeaderId The name of the column that represents the data.
153153 */
154- sortingDataAccessor : ( data : T , sortHeaderId : string ) => string | number = (
154+ sortingDataAccessor : ( data : T , sortHeaderId : string ) => string | number ;
155+
156+ /**
157+ * `sortingDataAccessor` is currently a regular property, however we need to know when it is
158+ * updated so that we can re-render the data. The problem is that we can't turn it into a
159+ * getter/setter, because it'll break existing users that define the accessor by extending the
160+ * class and initializing it to a new value. This is a workaround that'll preserve the old
161+ * behavior for users who override it and apply the fix for ones who don't. Eventually we should
162+ * reconcile these behaviors.
163+ * @breaking -change 15.0.0
164+ */
165+ private _defineSortingDataAccessor ( ) {
166+ if ( ! this . sortingDataAccessor ) {
167+ Object . defineProperty ( this , 'sortingDataAccessor' , {
168+ get : ( ) => this . _sortingDataAccessor ,
169+ set : accessor => {
170+ this . _sortingDataAccessor = accessor ;
171+ if ( this . _updateChangeSubscription ) {
172+ this . _updateChangeSubscription ( ) ;
173+ }
174+ } ,
175+ } ) ;
176+ }
177+ }
178+
179+ private _sortingDataAccessor : ( data : T , sortHeaderId : string ) => string | number = (
155180 data : T ,
156181 sortHeaderId : string ,
157182 ) : string | number => {
@@ -258,6 +283,7 @@ export class _MatTableDataSource<
258283 constructor ( initialData : T [ ] = [ ] ) {
259284 super ( ) ;
260285 this . _data = new BehaviorSubject < T [ ] > ( initialData ) ;
286+ this . _defineSortingDataAccessor ( ) ;
261287 this . _updateChangeSubscription ( ) ;
262288 }
263289
0 commit comments