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> {
110110 * @param data Data object that is being accessed.
111111 * @param sortHeaderId The name of the column that represents the data.
112112 */
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 ) =
114119 ( data : T , sortHeaderId : string ) : string | number => {
115120 const value = ( data as { [ key : string ] : any } ) [ sortHeaderId ] ;
116121
Original file line number Diff line number Diff line change @@ -341,6 +341,18 @@ describe('MatTable', () => {
341341 ] ) ;
342342 } ) ;
343343
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+
344356 it ( 'should by default correctly sort an empty string' , ( ) => {
345357 // Activate column A sort
346358 dataSource . data [ 0 ] . a = ' ' ;
You can’t perform that action at this time.
0 commit comments