|
| 1 | +import dash_ag_grid as dag |
| 2 | +from dash import Dash, html, dcc |
| 3 | +from . import utils |
| 4 | + |
| 5 | + |
| 6 | +def test_cd001_cell_renderer_function(dash_duo): |
| 7 | + app = Dash(__name__) |
| 8 | + |
| 9 | + rowData = [ |
| 10 | + {"size": 0, "is_available": True}, |
| 11 | + {"size": 1, "is_available": False}, |
| 12 | + {"size": 2, "is_available": True}, |
| 13 | + ] |
| 14 | + |
| 15 | + columnDefs = [ |
| 16 | + { |
| 17 | + "field": "size", |
| 18 | + "cellRenderer": {"function": "params.value < 1 ? 'small' : params.value < 2 ? 'medium' : 'large'"}, |
| 19 | + }, |
| 20 | + { |
| 21 | + "field": "is_available", |
| 22 | + "cellRenderer": {"function": "params.value ? 'yes' : 'no'"}, |
| 23 | + }, |
| 24 | + ] |
| 25 | + |
| 26 | + app.layout = html.Div( |
| 27 | + [ |
| 28 | + dcc.Markdown( |
| 29 | + "This grid uses a javascript function to display computed values for each cell, rather than the raw numbers." |
| 30 | + ), |
| 31 | + dag.AgGrid( |
| 32 | + columnDefs=columnDefs, |
| 33 | + rowData=rowData, |
| 34 | + id="grid", |
| 35 | + ), |
| 36 | + ], |
| 37 | + style={"margin": 20}, |
| 38 | + ) |
| 39 | + |
| 40 | + dash_duo.start_server(app) |
| 41 | + |
| 42 | + grid = utils.Grid(dash_duo, "grid") |
| 43 | + |
| 44 | + grid.wait_for_cell_text(0, 0, "small") |
| 45 | + grid.wait_for_cell_text(0, 1, "yes") |
| 46 | + grid.wait_for_cell_text(1, 0, "medium") |
| 47 | + grid.wait_for_cell_text(1, 1, "no") |
| 48 | + grid.wait_for_cell_text(2, 0, "large") |
| 49 | + grid.wait_for_cell_text(2, 1, "yes") |
0 commit comments