diff --git a/CHANGELOG.md b/CHANGELOG.md index 0ce249e3..b96a4f6c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -87,7 +87,7 @@ Links "DE#nnn" prior to version 2.0 point to the Dash Enterprise closed-source D - [#47](https://github.com/plotly/dash-ag-grid/pull/47) Fix `virtualRowData` by setting the default `rowModelType='clientSide'` - [#81](https://github.com/plotly/dash-ag-grid/pull/81) Fixing syncing issue with `rowData`, `virtualRowData` when cell edits and async `rowTransactions` occur - [#90](https://github.com/plotly/dash-ag-grid/pull/90) Fixing `columnState` to be populated once `gridReady` - +- [#92](https://github.com/plotly/dash-ag-grid/pull/92) Fixing `defaultStyle` when no `styleConditions` is in `cellStyle` ## [1.3.2] - 2023-01-13 diff --git a/src/lib/fragments/AgGrid.react.js b/src/lib/fragments/AgGrid.react.js index 2ed28366..6a344ec7 100644 --- a/src/lib/fragments/AgGrid.react.js +++ b/src/lib/fragments/AgGrid.react.js @@ -337,7 +337,10 @@ export default class DashAgGrid extends Component { } if ('cellStyle' in colOut) { - if (Object.keys(colOut.cellStyle).includes('styleConditions')) { + if ( + Object.keys(colOut.cellStyle).includes('styleConditions') || + Object.keys(colOut.cellStyle).includes('defaultStyle') + ) { const cellStyle = JSON.parse( JSON.stringify(colOut.cellStyle) ); diff --git a/tests/test_default_styles.py b/tests/test_default_styles.py new file mode 100644 index 00000000..e693778f --- /dev/null +++ b/tests/test_default_styles.py @@ -0,0 +1,49 @@ +import dash_ag_grid as dag +from dash import Dash, html, dcc +from . import utils +import time +from dash.testing.wait import until + +def test_ds001_default_styles(dash_duo): + app = Dash(__name__) + + columnDefs = [ + {"headerName": "Make", "field": "make"}, + {"headerName": "Model", "field": "model"}, + {"headerName": "Price", "field": "price", 'cellStyle': {'defaultStyle': {'color': 'green'}}}, + ] + + rowData = [ + {"make": "Toyota", "model": "Celica", "price": 35000}, + {"make": "Ford", "model": "Mondeo", "price": 32000}, + {"make": "Porsche", "model": "Boxter", "price": 72000}, + ] + + grid_with_default_cell_styles = html.Div( + [ + html.H3(children="Grid with Default Cell Styles"), + dag.AgGrid( + columnDefs=columnDefs, + rowData=rowData, + columnSize="sizeToFit", + defaultColDef=dict( + resizable=True, + cellStyle={"defaultStyle": {"color": "blue"}}, + ), + id='grid' + ), + html.Hr(), + ] + ) + + app.layout = grid_with_default_cell_styles + + dash_duo.start_server(app) + + grid = utils.Grid(dash_duo, "grid") + + grid.wait_for_cell_text(0, 0, "Toyota") + + ### testing styles + until(lambda: 'color: blue' in grid.get_cell(0, 0).get_attribute('style'), timeout=3) + until(lambda: 'color: green' in grid.get_cell(0, 2).get_attribute('style'), timeout=3)