1
votes

Consider a column in ag-grid that can only have one of two values, "Yes" and "No" as strings.

ag-grid has a built in column filter that shows all distinct values of that column with checkboxes.

Yes and No options

This filtering works great with user interaction, but I need to filter out the rows with "No" values prior to first render, without user interaction.

I can accomplish the desired filtering via the use of

gridOptions.isExternalFilterPresent
gridOptions.doesExternalFilterPass

However, when the user clicks the filter button they only see options for values that are currently in the column, not all possible values.

Yes only filter options

The problem is that the user may not even know that "No" is a possible option and will not know what that the grid is currently filtered.

I believe in order to help with this scenario, you supply all possible values can specify for the filter as filterParams below:

{
  headerName: 'ETF',
  field: 'isEtf',
  filterParams: {
    values: ['Yes', 'No'],
    suppressRemoveEntries: true
  }
}

When I supply values the grid will show both checkboxes, but it is not accurate as all "No" values have been filtered out and should have an un-checked checkbox next to the "No" option.

Setting true for suppressRemoveEntries seems to have no effect even though its description seems to suggest that this would address my issue.

Is there a way to control the state of the checkboxes programmatically or to have the grid reset/recognize current filter options against possible values supplied in filterParams.values after my external filter is applied?

1

1 Answers

0
votes

I never found a solution using an external filter, but utilizing the set filter created by the grid achieved the intended result.

const filter: IFilterComp = gridOptions.api.getFilterInstance('isEtf');

// bracket notation required because current typing does not include 
// the unselectValue function as of ag-grid v17.1.1
filter['unselectValue']('No');

// you must let grid know of the change so it will be applied to data in grid
gridOptions.api.onFilterChanged();