Skip to content

Commit 2f4e2cf

Browse files
authored
Merge pull request #346 from BSd3v/fix-styling-for-nodes
Fix Styling for Nodes
2 parents 891b9e7 + 1b5f898 commit 2f4e2cf

File tree

3 files changed

+87
-1
lines changed

3 files changed

+87
-1
lines changed

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ All notable changes to `dash-ag-grid` will be documented in this file.
44
This project adheres to [Semantic Versioning](https://semver.org/).
55
Links "DE#nnn" prior to version 2.0 point to the Dash Enterprise closed-source Dash AG Grid repo
66

7+
## [Unreleased]
8+
9+
### Fixed
10+
- [#346](https://github.com/plotly/dash-ag-grid/pull/346) Fixes issue [#347](https://github.com/plotly/dash-ag-grid/issues/347) where styling wasnt considering if the grid had rows without `data`. This is related to the alteration in [#332](https://github.com/plotly/dash-ag-grid/pull/332)
11+
12+
713
## [31.3.0] - 2024-11-22
814

915
### Fixed

src/lib/fragments/AgGrid.react.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1125,7 +1125,7 @@ export default class DashAgGrid extends Component {
11251125
return (params) => {
11261126
for (const {test, style} of tests) {
11271127
if (params) {
1128-
if (params.data) {
1128+
if (params.node.id && params.node.id !== null) {
11291129
if (test(params)) {
11301130
return style;
11311131
}

tests/test_conditional_formatting.py

+80
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from dash import Dash, html, dcc
33
from . import utils
44
from dash.testing.wait import until
5+
import pandas as pd
56

67

78
def test_cf001_conditional_formatting(dash_duo):
@@ -98,3 +99,82 @@ def test_cf001_conditional_formatting(dash_duo):
9899
lambda: "color: orange" in grid.get_cell(0, 2).get_attribute("style"), timeout=3
99100
)
100101
assert "color: orange" in grid.get_cell(0, 0).get_attribute("style")
102+
103+
def test_cf002_conditional_formatting_enterprise(dash_duo):
104+
app = Dash(__name__)
105+
106+
df = pd.read_csv(
107+
"https://raw.githubusercontent.com/plotly/datasets/master/ag-grid/olympic-winners.csv"
108+
)
109+
110+
columnDefs = [
111+
# Row group by country and by year is enabled.
112+
{
113+
"field": "country",
114+
"rowGroup": True,
115+
"hide": True,
116+
"suppressColumnsToolPanel": True,
117+
},
118+
{
119+
"field": "gold",
120+
"filter": True,
121+
"aggFunc": "sum",
122+
"valueFormatter": {"function": "d3.format('(,.2f')(params.value)"},
123+
"cellStyle": {
124+
125+
"styleConditions": [
126+
127+
{
128+
"condition": f"params.value < 100",
129+
"style": {"backgroundColor": "lightgreen"},
130+
},
131+
132+
],
133+
"defaultStyle": {"backgroundColor": "yellow"},
134+
},
135+
136+
},
137+
]
138+
139+
app.layout = html.Div(
140+
[
141+
dag.AgGrid(
142+
id="grid",
143+
columnDefs=columnDefs,
144+
rowData=df.to_dict("records"),
145+
defaultColDef=dict(
146+
suppressAggFuncInHeader=True
147+
),
148+
dashGridOptions={"rowSelection":"multiple", "animateRows": False},
149+
enableEnterpriseModules=True,
150+
getRowStyle={
151+
"styleConditions": [
152+
{
153+
"condition": "params.node.aggData ? params.node.aggData.gold < 3 : false",
154+
"style": {"backgroundColor": "silver"},
155+
}
156+
]
157+
},
158+
),
159+
]
160+
)
161+
162+
dash_duo.start_server(app)
163+
164+
grid = utils.Grid(dash_duo, "grid")
165+
166+
until(
167+
lambda: "United States" in grid.get_cell(0, 0).text, timeout=3
168+
)
169+
170+
### testing styles
171+
until(
172+
lambda: "background-color: yellow" in grid.get_cell(0, 2).get_attribute("style"), timeout=3
173+
)
174+
until(
175+
lambda: "background-color: lightgreen" in grid.get_cell(4, 2).get_attribute("style"), timeout=3
176+
)
177+
until(
178+
lambda: "background-color: silver" in grid.get_row(6).get_attribute("style"),
179+
timeout=3,
180+
)

0 commit comments

Comments
 (0)