首页 > 解决方案 > 虽然这是重复的问题,但我如何在第一行显示新行我正在使用 angular9

问题描述

我可以添加一个新行,但它在最后一页上。我想显示在第一行。谁能帮我解决这个问题?HTML 组件

  <button mat-button color="primary" (click)="addRow()">
            <mat-icon>add</mat-icon>
            <span>Add</span></button>

ts代码

 addRow(){
         this.agGrid.api.applyTransaction({
           add: [{make: '', model: '', price: ''}]
         });

标签: javascriptangularag-gridangular9ag-grid-angular

解决方案


您可以使用updateRowData网格 Api 上的方法,它允许您指定要插入的索引。addRow将您的方法更改为:

addRow() {
    let newRows = [{ make: "", model: "", price: '' }];
    this.gridApi.updateRowData({ add: newRows, addIndex: 0 });
  }

看看这个StackBlitz。


推荐阅读