M. Ko
M. Ko

Reputation: 563

Angular Material Datatable - apply filtering to custom data source

The Angular Material table tutorial shows a way of filtering data in this document. The tutorial uses MatTableDataSource<DataItem> to demonstrate filtering.

However, I created data table using Angular's schematics command ng generate @angular/material:material-table --name <component-name>, and the data source class provided by it extends DataSource<DataItem>. Can it be filtered using the former method?

Upvotes: 3

Views: 1666

Answers (1)

Capricorn
Capricorn

Reputation: 2089

The API documentation on the page you linked says MatTableDataSource extends DataSource As MatTableDataSource "adds" the filter method to the interface, a simple DataSource can not be filtered, as it just represents data. You may check out the source code of MatTableDataSource at the official github repo to fully understand what the filtering is about.

Nothing prevents you from creating a MatTableDataSource with your loaded data though

Upvotes: 2

Related Questions