4
votes

According to https://www.ag-grid.com/javascript-grid-filter-set/, "The grid does not update the filters for you as there are too many use cases...", #agreed.

I am using a Server Side data source with Infinite Paging querying a large set of data. Although, at initial load time, I may be confident the filter is listing all available "choices", I am hoping to find a solution to "reload" the filter at some frequency/event to be certain.

I am attempting to use the resetFilterValues() method of the object returned by a call to gridOptions.api.getFilterInstance(id).

When using a Server Side data source I am receiving the following console.error output:

ag-Grid: Set Filter cannot initialise because you are using a row model that does not contain all rows in the browser. Either use a different filter type, or configure Set Filter such that you provide it with values (Source ag-grid-enterprise.min.js:555

Note: The values method with async value load works splendidly and is written in accordance with recommendation e.g. callback to params.success with values.

I load the filter choices in the Column Header using the following approach:

{
    headerName: 'Something',
    field: 'SOMETHING',
    width: 200,
    suppressMenu: false,
    suppressFilter: false,
    filter: 'agSetColumnFilter',
    filterParams: {
        values: function (params) {
            someAsyncMethodReturningAPIResultsAsArray();
        }
        newRowsAction: 'keep'
    },
    menuTabs: ['filterMenuTab']
}

I then attempt to reload the filters at a later time (like when a button is pressed outside the grid) using the following code:

var filter = gridOptions.api.getFilterInstance(id);
filter.resetFilterValues();

This code results in the error expressed above.

Q: Does anyone know how to configure Set Model to return rows as described in the error message? Is there a better way to approach this problem anyone has experience with?

Thanks

1
Did you find a way to refresh (reload) the filters? I'm trying to figure out the same thing - Frank
Sorry no. Looks like this item hit their back burner too. I ended up rolling my own Custom Filter and owning the entire flow end to end. Didn't use their built in filters at all unfortunately. Happy to share generic code if it would be helpful, just pm me - Pepto
@Pepto I am struggling with this same problem. Can you please share your custom filter with regard to this problem? It will be of great help. Thank you in advance! - omostan

1 Answers

0
votes

This code below can be executed in the postProcessPopup callback and it will call the values() function defined in filterParams every time the popup is opened

var filter = gridOptions.api.getFilterInstance(id);
filter.refreshFilterValues();

Note: The refreshFilterValues function is doing the trick here. It is available in v24 and above. Not too sure about older versions.