Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

keep filter after ag-grid update

I'm trying to keep a grid's filter after updating a row.

When I click on a row in the grid, I open a dialog where I update the informations for this row, and then I look for the clicked row in the grid's rowData after that I update the corresponding record in the rowData with the values from the dialog, as following :

row[0].x = dg.x;
row[0].y = dg.y;
dg.gridOptions.rowData[index] = row[0];
dg.gridOptions.api.setRowData(newRows);

But after this I loose the filter on the grid, I did some search and I tried all the following solutions :

  1. Setting the gridOptions property deltaRowDataMode to true.

  2. filterParams: {apply: true, newRowsAction: 'keep'}

But none of these has worked.

How can I solve this ?

like image 326
Renaud is Not Bill Gates Avatar asked May 25 '18 16:05

Renaud is Not Bill Gates


2 Answers

You can set the filterParams newRowsAction to keep, like that

dg.defaultColDef = { filterParams: { newRowsAction: 'keep'}} ;

refer to https://www.ag-grid.com/javascript-grid-filtering/index.php

like image 163
Sameh Avatar answered Nov 13 '22 04:11

Sameh


Use this method (gridOptions.api.refreshCells()) instead of setRowData. Or if you need to use setRowData, save the filter model before the call and apply the filter again afterwards using these methods:

const model = this.gridOptions.api.getFilterModel();
//some code
this.gridOptions.api.setFilterModel(model);
like image 38
Atif Majeed Avatar answered Nov 13 '22 04:11

Atif Majeed