MCPcopy Create free account
hub / github.com/angular/components / MatTableDataSource

Class MatTableDataSource

src/material/table/table-data-source.ts:43–399  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

41 * own `DataSource`.
42 */
43export class MatTableDataSource<
44 // TODO: Remove `any` type below in a breaking change:
45 T extends object | any,
46 P extends MatPaginator = MatPaginator,
47> extends DataSource<T> {
48 /** Stream that emits when a new data array is set on the data source. */
49 private readonly _data: BehaviorSubject<T[]>;
50
51 /** Stream emitting render data to the table (depends on ordered data changes). */
52 private readonly _renderData = new BehaviorSubject<T[]>([]);
53
54 /** Stream that emits when a new filter string is set on the data source. */
55 private readonly _filter = new BehaviorSubject<string>('');
56
57 /** Used to react to internal changes of the paginator that are made by the data source itself. */
58 private readonly _internalPageChanges = new Subject<void>();
59
60 /**
61 * Subscription to the changes that should trigger an update to the table's rendered rows, such
62 * as filtering, sorting, pagination, or base data changes.
63 */
64 _renderChangesSubscription: Subscription | null = null;
65
66 /**
67 * The filtered set of data that has been matched by the filter string, or all the data if there
68 * is no filter. Useful for knowing the set of data the table represents.
69 * For example, a 'selectAll()' function would likely want to select the set of filtered data
70 * shown to the user rather than all the data.
71 */
72 filteredData!: T[];
73
74 /** Array of data that should be rendered by the table, where each object represents one row. */
75 get data() {
76 return this._data.value;
77 }
78
79 set data(data: T[]) {
80 data = Array.isArray(data) ? data : [];
81 this._data.next(data);
82 // Normally the `filteredData` is updated by the re-render
83 // subscription, but that won't happen if it's inactive.
84 if (!this._renderChangesSubscription) {
85 this._filterData(data);
86 }
87 }
88
89 /**
90 * Filter term that should be used to filter out objects from the data array. To override how
91 * data objects match to this filter string, provide a custom function for filterPredicate.
92 */
93 get filter(): string {
94 return this._filter.value;
95 }
96
97 set filter(filter: string) {
98 this._filter.next(filter);
99 // Normally the `filteredData` is updated by the re-render
100 // subscription, but that won't happen if it's inactive.

Callers

nothing calls this directly

Calls 3

_isNumberValueFunction · 0.90
warnMethod · 0.80
sortMethod · 0.65

Tested by

no test coverage detected