Skip to content

Commit fa5fedd

Browse files
committed
adding test for getRowStyle as function
1 parent 64b1be3 commit fa5fedd

File tree

2 files changed

+68
-0
lines changed

2 files changed

+68
-0
lines changed

tests/assets/dashAgGridFunctions.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,4 +498,8 @@ dagfuncs.sortColumns = (a, b) => b.localeCompare(a)
498498
dagfuncs.TestEvent = (params, setEventData) => {
499499
console.log(params)
500500
setEventData('here I am')
501+
}
502+
503+
dagfuncs.testToyota = (params) => {
504+
return params.data.make == 'Toyota' ? {'color': 'blue'} : {}
501505
}

tests/test_conditional_formatting.py

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,4 +177,68 @@ def test_cf002_conditional_formatting_enterprise(dash_duo):
177177
until(
178178
lambda: "background-color: silver" in grid.get_row(6).get_attribute("style"),
179179
timeout=3,
180+
)
181+
182+
def test_cf003_conditional_formatting(dash_duo):
183+
app = Dash(__name__)
184+
185+
columnDefs = [
186+
{
187+
"headerName": "Make",
188+
"field": "make",
189+
},
190+
{
191+
"headerName": "Model",
192+
"field": "model",
193+
},
194+
{"headerName": "Price", "field": "price"},
195+
{"field": "changes"},
196+
]
197+
198+
rowData = [
199+
{"make": "Toyota", "model": "Celica", "price": 35000},
200+
{"make": "Ford", "model": "Mondeo", "price": 32000},
201+
{"make": "Porsche", "model": "Boxster", "price": 72000},
202+
]
203+
204+
defaultColDef = {
205+
"valueSetter": {"function": "addEdits(params)"},
206+
"editable": True,
207+
}
208+
209+
getRowStyle = {
210+
"function": 'testToyota(params)'
211+
}
212+
213+
app.layout = html.Div(
214+
[
215+
dcc.Markdown(
216+
"In this grid, the __Make__ column has a popup below the cell, the __Model__ has a popup above the cell, and the __Price__ has the default (in cell) editor."
217+
),
218+
dag.AgGrid(
219+
columnDefs=columnDefs,
220+
rowData=rowData,
221+
defaultColDef=defaultColDef,
222+
columnSize="sizeToFit",
223+
getRowStyle=getRowStyle,
224+
id="grid",
225+
),
226+
html.Button(id="focus"),
227+
],
228+
style={"margin": 20},
229+
)
230+
231+
dash_duo.start_server(app)
232+
233+
grid = utils.Grid(dash_duo, "grid")
234+
235+
grid.wait_for_cell_text(0, 0, "Toyota")
236+
237+
### testing styles
238+
grid.get_cell(0, 0).click()
239+
until(lambda: "color: blue" in grid.get_row(0).get_attribute("style"), timeout=3)
240+
grid.get_cell(0, 0).send_keys("t")
241+
grid.get_cell(0, 1).click()
242+
until(
243+
lambda: "color: blue" not in grid.get_row(0).get_attribute("style"), timeout=3
180244
)

0 commit comments

Comments
 (0)