5

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?

userx
  • 485
  • 4
  • 12
  • 26

2 Answers2

12

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

Community
  • 1
  • 1
Yogen Darji
  • 3,230
  • 16
  • 31
0

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

Komalpreet Singh
  • 165
  • 1
  • 10
  • thanks, but what I need to do is remove the selection of specific row not highlight it when it is selected. also my data table is using the multi select feature, and at certain point I had more than one selected row. – userx Mar 27 '18 at 09:36