I have a Dash AG Grid with a floating filter and column groups. I have applied the cellClass
and headerClass
but cannot seem to find a way to style the floating filter as well. I can use the aria-colindex
but then it will style every AG Grid in my app. Can I somehow only style select floating filters for the the grid id grp
?
assests/style.css
.sports-column-groups-header-background-color, [aria-colindex="4"], [aria-colindex="5"], [aria-colindex="6"],
[aria-colindex="7"], [aria-colindex="8"]{
background-color: yellow;
}
app.py
import dash_ag_grid as dag
from dash import Dash, html
import pandas as pd
app = Dash(__name__)
df = pd.read_csv(
"https://raw.githubusercontent.com/plotly/datasets/master/ag-grid/olympic-winners.csv"
)
participant = [
{"field": "athlete"},
{"field": "age"},
{"field": "country"},
]
medals = [
{"field": "total"},
{"field": "gold"},
{"field": "silver"},
{"field": "bronze"},
]
noGroups = participant + medals
columnDefs = [
{
"headerName": "Athlete Details",
"children": [
{"field": "athlete", "pinned": True},
{"field": "country"},
{"field": "age"},
],
},
{
"headerName": "Sports Results",
'headerClass': f'sports-column-groups-header-background-color',
"suppressStickyLabel": True,
"openByDefault": True,
"children": [
{"field": "sport", 'cellClass': 'sports-column-groups-header-background-color',
'headerClass': 'sports-column-groups-header-background-color'},
{"field": "gold", "columnGroupShow": "open", 'cellClass': 'sports-column-groups-header-background-color',
'headerClass': 'sports-column-groups-header-background-color'},
{"field": "silver", "columnGroupShow": "open", 'cellClass': 'sports-column-groups-header-background-color',
'headerClass': 'sports-column-groups-header-background-color'},
{"field": "bronze", "columnGroupShow": "open", 'cellClass': 'sports-column-groups-header-background-color',
'headerClass': 'sports-column-groups-header-background-color'},
{"field": "total", "columnGroupShow": "closed", 'cellClass': 'sports-column-groups-header-background-color',
'headerClass': 'sports-column-groups-header-background-color'},
],
},
]
columnDefs2 = [
{
"headerName": "Athlete Details",
"children": [
{"field": "athlete", "width": 180},
{"field": "age", "width": 90},
{"field": "country", "width": 140},
],
},
{
"headerName": "Sports Results",
"children": [
{"field": "sport", "width": 140},
{"field": "total", "width": 100, "filter": "agNumberColumnFilter", "columnGroupShow": "closed"},
{"field": "gold", "width": 100, "filter": "agNumberColumnFilter", "columnGroupShow": "open"},
{"field": "silver", "width": 100, "filter": "agNumberColumnFilter", "columnGroupShow": "open"},
{"field": "bronze", "width": 100, "filter": "agNumberColumnFilter", "columnGroupShow": "open"},
],
},
]
app.layout = html.Div(
[
dag.AgGrid(
id="grps",
rowData=df.to_dict("records"),
columnDefs=columnDefs,
defaultColDef={"width": 200, 'floatingFilter': True, 'filter': True, },
dashGridOptions={"animateRows": False},
),
html.P('CSS is styling the table below, which makes sense, but how do I only style filters in the above table'),
dag.AgGrid(
id="no-grps",
rowData=df.to_dict("records"),
columnDefs=noGroups,
defaultColDef={"width": 200, 'floatingFilter': True, 'filter': True, },
dashGridOptions={"animateRows": False},
)
],
)
if __name__ == "__main__":
app.run(debug=True)