简体   繁体   中英

is there way to modify filter in Angular MatTableDataSource to filter data from the beginning of the searched expression and not included?

I have the same implementation as this stackblitz : https://stackblitz.com/edit/angular-f3mmmp?file=src%2Fapp%2Fapp.component.ts

For exemple if i search about "sa" in input i have two results. I just want to have the result of the name that starts with "sa" ( one result in this case) image description here

Anyone have an idea how to start filtering from the beginning of the expression using MatTableDatasource ?

Thanks :)

Solution is found.

in line 91 Replace : data.name.toLowerCase().indexOf(searchTerms.name) !== -1 by data.name.toLowerCase().startsWith(searchTerms.name)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM