mercredi 19 juin 2019

How to auto-check the checkbox when data is enteres in that specific row

I am using angular mastertoggle for table with selection. The table row gets selected when the checkbox of that row is clicked This table also has an input field

How can I auto select that row when the user fills the field. I want the checkbox to be checked both when clicked or when the user fills a field in that row enter image description here

this is the code for the main select checkbox and the checkbox of eachrow

<ng-container matColumnDef="select">
<th mat-header-cell *matHeaderCellDef>
  <mat-checkbox (change)="$event ? masterToggle() : null"
                [checked]="selection.hasValue() && isAllSelected()"
                [indeterminate]="selection.hasValue() && !isAllSelected()">
  </mat-checkbox>
</th>
<td mat-cell *matCellDef="let row">
  <mat-checkbox (click)="$event.stopPropagation()"
                (change)="$event ? selection.toggle(row) : null"

                [checked]="selection.isSelected(row)">
  </mat-checkbox>
</td>

i tried modifying

[checked]="selection.isSelected(row)"

to

[checked]="selection.isSelected(row) || !!row.name">

it does check when a name is entered but this background colour change of a selected row or the intermediate check for the main select is not reflected




Aucun commentaire:

Enregistrer un commentaire