Я создал Ag-сетку с пользовательским фильтром столбцов. При добавлении строки в таблицу фильтр не обновляется.
https://stackblitz.com/edit/ag-grid-custom-filter
Эксперт Посоветуйте пожалуйста?
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");