如何使用角形材质垫表添加和删除动态行

时间:2019-01-28 06:03:27

标签: angular angular-material material

如何使用角形材料mat-table添加和删除动态行。向我建议一些方法,我已经完成了添加列并为其添加填充,但是我无法添加第二行。

 
  displayedColumns = ['position', 'name', 'weight', 'symbol','extra','Action'];
  displayedColumnsAddUser: string[] = ['position', 'name', 'weight', 'symbol', 'extra', 'Action'];
  dataSource = new MatTableDataSource<Element>(ELEMENT_DATA);
}

const ELEMENT_DATA: Element[] = [
  {name: '',position:1, weight:'' , symbol:'', extra:'',Action:''},
];

export interface Element {
  name: string;
  position:number;
  weight: string;
  symbol: string;
  extra :string;
  Action:string;
}
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
 <div class="example-container mat-elevation-z8" style="width: 75%;
 margin-left: 78px;">
  

    <mat-table class="custom" [dataSource]="dataSource">

      <ng-container matColumnDef="position">
        <mat-header-cell *matHeaderCellDef> No. </mat-header-cell>
        
        <mat-cell *matCellDef="let element">
            <!-- <mat-form-feild>
                <input matInput placeholder="placeholder" [(ngModel)]="element.position">
            </mat-form-feild> -->
            {{element.position}} 
               
       </mat-cell> 
      </ng-container>
  
      <ng-container matColumnDef="name">
        <mat-header-cell *matHeaderCellDef> Protocol </mat-header-cell>
        <mat-cell *matCellDef="let element"> {{element.protocol}} </mat-cell>
      </ng-container>
  
      <ng-container matColumnDef="weight">
        <mat-header-cell *matHeaderCellDef> SourceIp </mat-header-cell>
        <mat-cell *matCellDef="let element"> {{element.SourceIp}} </mat-cell>
      </ng-container>
  
      
      <ng-container matColumnDef="symbol">
        <mat-header-cell *matHeaderCellDef> DestinationIp </mat-header-cell>
        <mat-cell *matCellDef="let element"> {{element.DestinationIp}} </mat-cell>
      </ng-container>
          <ng-container matColumnDef="extra">
        <mat-header-cell *matHeaderCellDef>AcessType </mat-header-cell>
        <mat-cell *matCellDef="let element"> {{element.AcessType}} </mat-cell>
      </ng-container>
      <ng-container matColumnDef="Action">
        <mat-header-cell *matHeaderCellDef>Action </mat-header-cell>
        <mat-cell *matCellDef="let element"> {{element.Action}} </mat-cell>
      </ng-container>
  
      <mat-header-row *matHeaderRowDef="displayedColumns"></mat-header-row>
      <mat-row *matRowDef="let row; columns: displayedColumns;"></mat-row>
    </mat-table>
  </div>
  <script type="text/javascript" src="https://js.squareup.com/v2/paymentform"></script>

0 个答案:

没有答案