Set Filter is an AG Grid Enterprise feature, so you’ll need a license key to use it. See Using AG Grid Enterprise for an example of how to use your license key with Dash AG Grid components.
The Set Filter is a more powerful version of Excel’s AutoFilter, allowing users to easily build more complex sets for filtering in less time. However, sometimes you may want to provide your users with an Excel-like experience. For this you can use Excel Mode.
To enable Excel Mode, simply add the excelMode
option to your filter params:
columnDefs = [
{
'field': 'animal',
'filter': 'agSetColumnFilter',
'filterParams': {
# can be 'windows' or 'mac'
'excelMode': 'windows',
},
}
]
Excel’s AutoFilter behaves differently depending on whether you are using the Windows or Mac version. The grid therefore allows you to choose which behaviour you would like by setting excelMode
to 'windows'
or 'mac'
respectively.
The example below demonstrates the differences between the different modes:
from dash import Dash, html
import dash_ag_grid as dag
import pandas as pd
animals = [
"Monkey",
"Lion",
"Elephant",
"Tiger",
"Giraffe",
"Antelope",
"Otter",
"Penguin",
"",
]
df = pd.DataFrame(animals * 3, columns=["animal"])
app = Dash(__name__)
columnDefs = [
{
"headerName": "Default",
"field": "animal",
"filter": "agSetColumnFilter",
},
{
"headerName": "Excel (Windows)",
"field": "animal",
"filter": "agSetColumnFilter",
"filterParams": {
"excelMode": "windows",
},
},
{
"headerName": "Excel (Mac)",
"field": "animal",
"filter": "agSetColumnFilter",
"filterParams": {
"excelMode": "mac",
},
},
]
defaultColDef = {
"flex": 1,
"minWidth": 150,
"resizable": True,
}
localeText = {
"applyFilter": "OK",
"cancelFilter": "Cancel",
"resetFilter": "Clear Filter",
}
grid = dag.AgGrid(
id="set-filters-excel",
enableEnterpriseModules=True,
rowData=df.to_dict("records"),
columnDefs=columnDefs,
defaultColDef=defaultColDef,
dashGridOptions={"sideBar": "filters", "localText": localeText},
style={"height": 600},
)
app.layout = html.Div([html.H4("Set Filter Example: Excel Mode"), grid])
if __name__ == "__main__":
app.run_server(debug=True)
The table below shows the differences in behaviour alongside the default behaviour of the grid for comparison. Note that the behaviour of the grid can be changed from the defaults in many ways using the other options detailed on the Set Filter pages. These options can also be used in conjunction with the Excel Mode to give you the maximum amount of flexibility.
See this table in the AG Grid Docs