Reputation: 515
I'm using the Selection Data table
to deselect all the rows we use:
this.selection.clear();
where selection is an object of SelectionModel class. Now what if I want to remove the selection of specific row from code behind "component typescript code", is there any helpful "angular" statement just like clear() method?
Upvotes: 5
Views: 7793
Reputation: 3300
You can use
this.selection.deselect(row)
this.selection.select(row)
Sample to deselect 5th row with mat-table
function to do select or deselect specific row.
Example: If you want to deselect 3rd
row you can do following.
this.selection.deselect(this.dataSource.data[2])
This the SelectionModel class code
Upvotes: 12
Reputation: 165
You can do it by using ngClass and a flag like selectedRowIndex. Whenever clicked row index is equal to selectedRowIndex, the class will be applied. This link might help you
Angular 4 Material table highlight a row
Upvotes: 0