【问题标题】:How to add new row from last using swimlane/ngx-datatable如何使用泳道/ngx-datatable 从最后添加新行
【发布时间】:2022-03-04 06:34:36
【问题描述】:

尝试向泳道/ngx-datatable 添加新行,但无法正常工作。我想从最后添加新行,但在我的代码中它添加到同一行。如果您看到我的 stackblitz 演示,您可以理解我的问题。单击 addnewrow 选项并查看它。我不知道如何组合 rowData 和数据以在表中添加新行。如何解决此问题。

注意:我们可以在表格之外使用 addNewRow 选项(按钮或链接)。

app.component.html:

  <ng-template #buttonsTemplate let-row="row" let-value="value" let-rowIndex="rowIndex">
     <div class="actions"> 
       <a href="javascript:void(0)" (click)='addNewRow(row,rowIndex)'> AddNewRow </a>  
     </div>
  </ng-template>

app.component.ts:

 addNewRow(data, rowIndex) {
    //Copy the data
    let rowData = {
      name: "Beryl Rice New",
      gender: "Male",
      company: "Velity",
      actions: ""
    };

    //rowData.BATCH_CODE = "";
    //rowData.qty = 0;
    this.rows.splice(rowIndex, 0, rowData);
    this.rows = [...this.rows];
  }

演示:https://stackblitz.com/edit/angular-ymttep?file=app%2Fapp.component.ts

【问题讨论】:

    标签: angular7 angular8 angular10 ngx-datatable angular11


    【解决方案1】:

    请更新您的 addNewRow() 方法

    this.rows.splice(rows.length, 0, rowData);
    

    【讨论】:

      猜你喜欢
      • 2018-10-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-11-06
      • 1970-01-01
      • 2021-07-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多