Ag网格:添加行

时间:2019-07-04 06:29:38

标签: angular ag-grid

我用自定义列过滤器创建了Ag-grid。当我在表格过滤器中添加行时,该行不会更新。

https://stackblitz.com/edit/ag-grid-custom-filter

enter image description here

请给专家意见?

HTML

 
  <ag-grid-angular  #agGrid class="ag-theme-balham cis-ag-grid" [defaultColDef]="defaultColDef"
      [columnDefs]="columnDefs" [rowSelection]="rowSelection" [rowData]="rowData" [suppressMenuHide]="true"
      [rowDragManaged]="true" [frameworkComponents]="frameworkComponents" (selectionChanged)="onSelectionChanged()"
      (rowClicked)='onRowClicked($event)' (gridReady)="onGridReady($event)" (valueChanged)="onCellValueChanged($event)"
       [gridOptions]="gridOptions" >
    </ag-grid-angular>
    <!-- ./ Ag-grid -->

TS

onCellValueChanged(params) {
    var col = params.column;
    switch (col.getId()) {
      case "name":
        this.refreshName(params.api, params.newValue);
        break;
    }
  }

refreshName(api, newValue) {
    var filter = api.getFilterInstance("name");
    var model = filter.getModel();
    filter.resetFilterValues();
    var filterWasActive = model !== null;
    if (filterWasActive) {
      if (model && model.values.indexOf(newValue) < 0) {
        model.values.push(newValue);
      }
      filter.setModel(model);
    }
  }

添加行

 const addedRow = this.gridOptions.api.updateRowData({ add: [selectedView.data] });
      addedRow.add[0].setSelected(true);
      this.gridApi.getFilterInstance("name").resetFilterValues(); // Trying to refresh the filter
      this.gridOptions.api.ensureIndexVisible(addedRow.add[0].rowIndex, "top");

1 个答案:

答案 0 :(得分:1)

删除该行后,您必须添加此行this.gridApi.onFilterChanged();

this.filter4.onNewRowsLoaded();

让ag-grid知道数据是在外部修改的。

根据文档-

  

onFilterChanged()-通知网格过滤器已更改。这个   通常是在通过一个过滤器更改过滤器后调用的   API。