角度-物料表,是否可以通过单击按钮来编辑行?

时间:2018-10-30 12:18:51

标签: html css angular typescript angular6

我在其中需要编辑表格。在表中,它们是“编辑”图标按钮,如果我单击“编辑”按钮,则前三列应该是可编辑的,并且在编辑后需要更新。 编辑应该只在同一行中而不是在mat-dialog box中。如果按编辑按钮名称,年龄,电话号码,则应可编辑。请帮助我

.html文件

        <div class="table-container mat-elevation-z8">
          <mat-table mat-stretch-tabs [dataSource]="dataSource" matSort matSortActive="name" matSortDirection="asc" matSortDisableClear>
           <ng-container matColumnDef="name">
             <mat-header-cell *matHeaderCellDef mat-sort-header >  Name <mat-icon>filter_list</mat-icon> </mat-header-cell>
              <mat-cell *matCellDef="let datalist " > {{datalist.name}} </mat-cell>
           </ng-container>


            <ng-container matColumnDef="description">
              <mat-header-cell *matHeaderCellDef mat-sort-header > Age <mat-icon>filter_list</mat-icon> </mat-header-cell>
              <mat-cell *matCellDef="let datalist" > {{datalist.age}} </mat-cell>
            </ng-container>
              <ng-container matColumnDef="databaseId">
                <mat-header-cell *matHeaderCellDef mat-sort-header >  <mat-icon>filter_list</mat-icon> </mat-header-cell>
                <mat-cell *matCellDef="let datalist" > {{datalist.phonenumber}} </mat-cell>
             </ng-container>

              <ng-container matColumnDef="isActive">
                  <mat-header-cell *matHeaderCellDef  > IsActive/InActive </mat-header-cell>
                  <mat-cell *matCellDef="let datalist" ><mat-slide-toggle color="primary" [checked]="datalist.isActive"></mat-slide-toggle></mat-cell>
              </ng-container>
             
              <ng-container matColumnDef="edit">
                <mat-header-cell *matHeaderCellDef > Edit </mat-header-cell>
                <mat-cell *matCellDef="let row">
                  <button mat-icon-button color="primary" >
                    <mat-icon>edit</mat-icon>
                  </button>
                </mat-cell>
              </ng-container>

              <ng-container matColumnDef="delete">
                <mat-header-cell *matHeaderCellDef > Delete </mat-header-cell>
                <mat-cell *matCellDef="let datalist">
                  <button mat-icon-button color="primary" (click)="clickEvent(datalist,datalist.principalId)"  [ngClass]="{'myClass':datalist.isClicked}">
                    <mat-icon>remove_circle</mat-icon>
                  </button>
                </mat-cell>
              </ng-container>
                
              <mat-header-row *matHeaderRowDef="displayedColumns" ></mat-header-row>
              <mat-row *matRowDef="let row; columns: displayedColumns;" (click)="onRowClicked(datalist)"></mat-row>
          </mat-table>
        </div>

        <div>
         <div class='left'>
           <button class="mat-button menu-button">
              <mat-icon color="primary"> add_to_photos </mat-icon>
              Add Site
           </button>
          </div>
          <div *ngIf="showButtons" class='right'>
            <button mat-button type="button"  class="close-button" (click)="cancel()">
              <mat-icon>block</mat-icon>
             CANCEL
            </button>       
           <button (click)="delete()">Save</button>
          </div> 
        </div>   

    

1 个答案:

答案 0 :(得分:2)

此答案并非特定于mat-table,而是尝试将PrimeNG用于可编辑表。

https://www.primefaces.org/primeng/#/table/edit