0
votes

enter image description here enter image description here

enter image description here enter image description here

I am using Angular material table, mat-select and mat-option drop down, For the Media dropdown, the value was Email, lk_type was 3287, after I select phone, the media value should be phone and lk_type should be 3286, however, when I click on the edit button, this.currentData didn't change dropdown value, it still keeping the old value, do you know how I can change my drop down value for this angular mat-select and mat-option dropdown?

add-person.component.html

<mat-table [dataSource]="dataSource">
  <ng-container matColumnDef="person_contact_ID">
    <mat-header-cell *matHeaderCellDef> Person Contact ID </mat-header-cell>
    <mat-cell *matCellDef="let row">
      <mat-form-field floatLabel="{{ row.editing ? 'float' : 'never'}}">
        <input [(ngModel)]="row.currentData.person_contact_ID" placeholder="Person Contact ID" [disabled]="!row.editing" matInput>
      </mat-form-field>
    </mat-cell>
  </ng-container>
<ng-container matColumnDef="media">
    <mat-header-cell *matHeaderCellDef> Media </mat-header-cell>
    <mat-cell *matCellDef="let row">
      <mat-form-field>
        <mat-select style="min-width: 200px;" placeholder="" value="{{row.currentData.lk_type}}">
          <mat-option *ngFor="let media of mediaList " value="{{media.lookup_id}}">
            {{ media.descr }}
          </mat-option>
        </mat-select>
      </mat-form-field>
    </mat-cell>
  </ng-container>
  

<ng-container matColumnDef="actionsColumn">
    <mat-cell *matCellDef="let row">
      <button *ngIf="row.editing" mat-icon-button color="primary" focusable="false" (click)="row.confirmEditCreate_AddPerson()">
        <i class="fa fa-check mat-icon"></i>
      </button>
    </mat-cell>
  </ng-container>
<mat-header-row *matHeaderRowDef="displayedColumn
s"></mat-header-row>
  <mat-row *matRowDef="let row; columns: displayedColumns;"></mat-row>
</mat-table>

tabledata.ts

confirmEditCreate_AddPerson(): boolean {
    //_personService: TestRDB2Service;
    if (this.id == -1)
      return this.source.confirmCreate(this);
    else
      
      try {
        this._http.put("https://localhost:5001/" + 'api/TestRDB2/AddUpdatePerson_Contact/', this.currentData).subscribe();        
      } catch (e) {
        return e
      }
    return true;
      //return this.source.confirmEdit(this);
  }
1

1 Answers

1
votes

If you are using mat-select in mat-table you need to use two-way binding ngModel in order to set data in currentData object check out below code for reference:

<mat-form-field>
        <mat-select style="min-width: 200px;" placeholder="" [(ngModel)]="row.currentData.lk_type">
          <mat-option *ngFor="let media of mediaList " value="{{media.lookup_id}}">
            {{ media.descr }}
          </mat-option>
        </mat-select>
      </mat-form-field>