File tree Expand file tree Collapse file tree 2 files changed +18
-1
lines changed Expand file tree Collapse file tree 2 files changed +18
-1
lines changed Original file line number Diff line number Diff line change @@ -110,7 +110,12 @@ export class MatTableDataSource<T> extends DataSource<T> {
110
110
* @param data Data object that is being accessed.
111
111
* @param sortHeaderId The name of the column that represents the data.
112
112
*/
113
- sortingDataAccessor : ( ( data : T , sortHeaderId : string ) => string | number ) =
113
+ get sortingDataAccessor ( ) { return this . _sortingDataAccessor ; }
114
+ set sortingDataAccessor ( value : ( data : T , sortHeaderId : string ) => string | number ) {
115
+ this . _sortingDataAccessor = value ;
116
+ this . _updateChangeSubscription ( ) ;
117
+ }
118
+ private _sortingDataAccessor : ( ( data : T , sortHeaderId : string ) => string | number ) =
114
119
( data : T , sortHeaderId : string ) : string | number => {
115
120
const value = ( data as { [ key : string ] : any } ) [ sortHeaderId ] ;
116
121
Original file line number Diff line number Diff line change @@ -341,6 +341,18 @@ describe('MatTable', () => {
341
341
] ) ;
342
342
} ) ;
343
343
344
+ it ( 'should emit if the sortingDataAccessor changes' , ( ) => {
345
+ const spy = jasmine . createSpy ( 'data changes spy' ) ;
346
+ const subscription = dataSource . connect ( ) . subscribe ( spy ) ;
347
+
348
+ // Reset the `calls` since the data source emits upon subscription as well.
349
+ spy . calls . reset ( ) ;
350
+ dataSource . sortingDataAccessor = ( ) => '' ;
351
+
352
+ expect ( spy ) . toHaveBeenCalled ( ) ;
353
+ subscription . unsubscribe ( ) ;
354
+ } ) ;
355
+
344
356
it ( 'should by default correctly sort an empty string' , ( ) => {
345
357
// Activate column A sort
346
358
dataSource . data [ 0 ] . a = ' ' ;
You can’t perform that action at this time.
0 commit comments