Skip to content

Commit a2b8d13

Browse files
authored
Merge pull request #428 from plotly/427-dash-ag-grid-v33-doesnt-support-withpart-for-theming-updates
Allows for `createPart` to be used to craft parts to be utilized with `withPart`
2 parents c87759d + 1f61c08 commit a2b8d13

File tree

4 files changed

+65
-10
lines changed

4 files changed

+65
-10
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Links "DE#nnn" prior to version 2.0 point to the Dash Enterprise closed-source D
1010
- fixes [#416] (https://github.com/plotly/dash-ag-grid/issues/416)
1111
- fixes [#407](https://github.com/plotly/dash-ag-grid/issues/407)
1212
- [#412](https://github.com/plotly/dash-ag-grid/issues/412) fix "Multi-Column Filter not properly recognized in filterParams"
13+
- [#427](https://github.com/plotly/dash-ag-grid/issues/427) exposes `agGrid` from the community package for use in custom themes and functions
1314

1415
## [33.3.2rc2] - 2025-09-17
1516

src/lib/fragments/AgGrid.react.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,12 @@ import RowMenuRenderer from '../renderers/rowMenuRenderer';
4242
import {customFunctions} from '../renderers/customFunctions';
4343

4444
import {AgGridReact, useGridFilter} from 'ag-grid-react';
45-
import {
46-
themeAlpine,
47-
themeBalham,
48-
themeMaterial,
49-
themeQuartz,
50-
} from 'ag-grid-community';
51-
const themes = {themeAlpine, themeBalham, themeMaterial, themeQuartz};
45+
import * as agGrid from 'ag-grid-community';
46+
let themes = {};
47+
if (agGrid && typeof agGrid === 'object' && !Array.isArray(agGrid)) {
48+
const {themeAlpine, themeBalham, themeMaterial, themeQuartz} = agGrid;
49+
themes = {themeAlpine, themeBalham, themeMaterial, themeQuartz};
50+
}
5251

5352
// d3 imports
5453
import * as d3Format from 'd3-format';
@@ -157,6 +156,7 @@ export function DashAgGrid(props) {
157156
esprima.parse(funcString).body[0].expression;
158157
const context = {
159158
...themes,
159+
agGrid,
160160
d3,
161161
dash_clientside,
162162
...customFunctions,
@@ -175,6 +175,7 @@ export function DashAgGrid(props) {
175175
esprima.parse(funcString).body[0].expression;
176176
const context = {
177177
...themes,
178+
agGrid,
178179
d3,
179180
dash_clientside,
180181
...customFunctions,
@@ -195,6 +196,7 @@ export function DashAgGrid(props) {
195196
esprima.parse(funcString).body[0].expression;
196197
const context = {
197198
...themes,
199+
agGrid,
198200
d3,
199201
...customFunctions,
200202
...window.dashAgGridFunctions,

tests/assets/dashAgGridFunctions.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -539,3 +539,6 @@ dagfuncs.testToyota = (params) => {
539539
return params.data.make == 'Toyota' ? {'color': 'blue'} : {}
540540
}
541541

542+
dagfuncs.customTheme = (theme, agGrid) => {
543+
return theme.withPart(agGrid.createPart(agGrid.colorSchemeDark)).withPart(agGrid.createPart(agGrid.iconSetAlpine));
544+
}

tests/test_user_style.py

Lines changed: 52 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,58 @@ def test_us002_legacy_themes(dash_duo, theme):
109109

110110
# Base styles: assert that the grid height is <= 400px because an unstyled
111111
# grid is very "tall"
112-
root_wrapper = dash_duo.find_element(".ag-root-wrapper")
113-
wrapper_height = root_wrapper.size["height"]
114-
assert wrapper_height <= 400, f"Grid appears to be unstyled: height is too tall ({wrapper_height}px)"
112+
until(
113+
lambda: dash_duo.find_element(".ag-root-wrapper").size["height"] <= 400,
114+
timeout=3,
115+
msg=f"Grid appears to be unstyled: height is too tall ({dash_duo.find_element('.ag-root-wrapper').size['height']}px)"
116+
)
117+
# Specific themes: Assert that cell headers are bold
118+
header_cell_text = dash_duo.find_element(".ag-header-cell-text")
119+
font_weight = header_cell_text.value_of_css_property("font-weight")
120+
assert font_weight in ["bold", "700", "600", "500",], "Grid appears to be unstyled: cell headers are not bold"
121+
122+
@pytest.mark.parametrize("theme", ["themeAlpine", "themeBalham", "themeMaterial", "themeQuartz"])
123+
def test_us003_part_themes(dash_duo, theme):
124+
app = Dash(
125+
__name__
126+
)
127+
128+
columnDefs = [
129+
{"field": "name", "width": "500"},
130+
]
131+
132+
rowData = [
133+
{"name": "a"},
134+
{"name": "b"},
135+
{"name": "c"},
136+
]
137+
138+
app.layout = html.Div(
139+
[
140+
dag.AgGrid(
141+
id="grid",
142+
columnDefs=columnDefs,
143+
rowData=rowData,
144+
dashGridOptions={'theme': {'function': f'customTheme({theme}, agGrid)'}},
145+
),
146+
]
147+
)
148+
149+
dash_duo.start_server(app)
150+
151+
grid = utils.Grid(dash_duo, "grid")
152+
153+
grid.wait_for_cell_text(0, 0, "a")
154+
155+
# Test that the CSS files are actually loaded and applied
156+
157+
# Base styles: assert that the grid height is <= 400px because an unstyled
158+
# grid is very "tall"
159+
until(
160+
lambda: dash_duo.find_element(".ag-root-wrapper").size["height"] <= 400,
161+
timeout=3,
162+
msg=f"Grid appears to be unstyled: height is too tall ({dash_duo.find_element('.ag-root-wrapper').size['height']}px)"
163+
)
115164

116165
# Specific themes: Assert that cell headers are bold
117166
header_cell_text = dash_duo.find_element(".ag-header-cell-text")

0 commit comments

Comments
 (0)