With the help of this tutorial I wrote my own datasource for the angular material table. I get the list of data from an api and display it in a material table.
Code MyDataSource
export class MyDataSource extends DataSource<any> {
private users: Observable<User[]>;
constructor(private userService: UserService) {
super();
}
connect(): Observable<User[]> {
this.users = this.userService.getAll();
return this.users;
}
disconnect() { }
filterWithCriteria(filterData: any): any {
return this.users
.filter(element => element[filterData.criteria].toLocaleLowerCase().includes(filterData.searchTerm.toLocaleLowerCase()))
.map(element => element)
.subscribe(
element => console.log(element),
err => console.error(err),
() => console.log('Streaming is over')
);
}
}
The api delivers an observable with user objects.
Code User
export class User implements models.User {
constructor(
public name?: string,
public adress?: string,
public email?: string,
public telefon?: string,
public birthday?: Date
) {}
}
The objective is to search in the list of the user with a criteria. The criteria can be name, adress, ...
.filter(element => element[filterData.criteria].toLocaleLowerCase().includes(filterData.searchTerm.toLocaleLowerCase()))
This line gives me the error the toLocaleLowerCase is not defined in User and
console.log(this.users[filterData.criteria]);
gives me 'undefined'.
Thanks for the help,
Best Regards