Skip to content

Commit

Permalink
Merge pull request #92 from BSd3v/fixing-default-styles
Browse files Browse the repository at this point in the history
Fixing `defaultStyle` in the `cellStyle` prop when only listed
  • Loading branch information
alexcjohnson authored Mar 16, 2023
2 parents 9840696 + d8eeae2 commit f14d5b5
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 2 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 4 additions & 1 deletion src/lib/fragments/AgGrid.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
);
Expand Down
49 changes: 49 additions & 0 deletions tests/test_default_styles.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit f14d5b5

Please sign in to comment.