Hello Everyone,
I am new to the DASH and Python world but trying hard here.
I am trying to replace my DataTables from my DASH app with AgGrid, but I came across this problem of styling the headers that seems to be much harder in AgGrid.
I was following some posts and DASH,plotly documentation:
( Styling Headers | Dash for Python Documentation | Plotly)
but I couldn’t get to a successful outcome.
This is what I tried:
I used this simple code to create (from Plotly link above) an AgGrid with the CSS file I used named styles.css. I get the Ag.Grid, but I dont get any of the styling in the CSS file.
Is there any extra step that is not mentioned anywhere because it might be “obvious” for some experienced developers?
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"
)
columnDefs = [
{
"headerName": "Group 1",
"children": [
{"field": "athlete", "resizable": True},
{"field": "age", "resizable": True},
],
},
{
"headerName": "Group 2",
"children": [
{"field": "country"},
{"field": "date"},
{"field": "sport"},
{"field": "total"},
],
},
]
app.layout = html.Div(
[
dag.AgGrid(
id="styling-headers",
rowData=df.to_dict("records"),
columnDefs=columnDefs,
defaultColDef={"sortable": True, "filter": True, "editable": True},
columnSize="sizeToFit",
className="ag-theme-alpine headers1",
),
]
)
if __name__ == "__main__":
app.run(debug=True)
-------------------------------------------------------------------------------------------------------------------------------
.ag-theme-alpine {
--ag-header-height: 30px;
--ag-header-foreground-color: white;
--ag-header-background-color: black;
--ag-header-cell-hover-background-color: rgb(80, 40, 140);
--ag-header-cell-moving-background-color: rgb(80, 40, 140);
}
.ag-theme-alpine .ag-header {
font-family: cursive;
}
.ag-theme-alpine .ag-header-group-cell {
font-weight: normal;
font-size: 22px;
}
.ag-theme-alpine .ag-header-cell {
font-size: 18px;
}