Skip to content

Commit 98d30c9

Browse files
authored
Merge pull request #352 from BSd3v/adding-event-data
Adding EventData Prop
2 parents 9ffe139 + f549b02 commit 98d30c9

File tree

6 files changed

+75
-1
lines changed

6 files changed

+75
-1
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ Links "DE#nnn" prior to version 2.0 point to the Dash Enterprise closed-source D
1010
- [#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)
1111
- [#353](https://github.com/plotly/dash-ag-grid/pull/353) Adjustments for support of Dash 3
1212

13+
### Added
14+
- [#352](https://github.com/plotly/dash-ag-grid/pull/352) Adds `eventData` prop for devs to send arbitrary events from the grid events complete with an auto timestamp
15+
1316
## [31.3.0] - 2024-11-22
1417

1518
### Fixed

src/lib/components/AgGrid.react.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,21 @@ DashAgGrid.propTypes = {
533533
*/
534534
eventListeners: PropTypes.objectOf(PropTypes.array),
535535

536+
/**
537+
* Object of Event Data from the grid, based upon when a user triggered an event with an event listener.
538+
*/
539+
eventData: PropTypes.shape({
540+
/**
541+
* Data that the developers passes back
542+
*/
543+
data: PropTypes.any,
544+
545+
/**
546+
* Timestamp of when the event was fired
547+
*/
548+
timestamp: PropTypes.any,
549+
}),
550+
536551
/********************************
537552
* GRID PROPS
538553
*******************************/

src/lib/fragments/AgGrid.react.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,15 @@ export default class DashAgGrid extends Component {
174174
this.props.setProps(propsToSet);
175175
}
176176
};
177+
this.setEventData = (data) => {
178+
const timestamp = Date.now();
179+
this.customSetProps({
180+
eventData: {
181+
data,
182+
timestamp,
183+
},
184+
});
185+
};
177186

178187
this.convertedPropCache = {};
179188

@@ -1100,6 +1109,7 @@ export default class DashAgGrid extends Component {
11001109
...customFunctions,
11011110
...window.dashAgGridFunctions,
11021111
setGridProps: this.customSetProps,
1112+
setEventData: this.setEventData,
11031113
};
11041114
return (params) => evaluate(parsedCondition, {params, ...context});
11051115
});

src/lib/utils/propCategories.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,7 @@ export const PROPS_NOT_FOR_AG_GRID = [
347347
'columnSize',
348348
'scrollTo',
349349
'eventListeners',
350+
'eventData',
350351
];
351352

352353
/**
@@ -364,6 +365,7 @@ export const OMIT_PROP_RENDER = [
364365
'paginationInfo',
365366
'cellRendererData',
366367
'cellDoubleClicked',
368+
'eventData',
367369
];
368370

369371
/**

tests/assets/dashAgGridFunctions.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -499,3 +499,9 @@ dagfuncs.showOutput = (params, setGridProps) => {
499499
dagfuncs.sortColumns = (a, b) => b.localeCompare(a)
500500

501501
// BEGIN test_pivot_column_order.py
502+
503+
504+
dagfuncs.TestEvent = (params, setEventData) => {
505+
console.log(params)
506+
setEventData('here I am')
507+
}

tests/test_event_listeners.py

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
import dash_ag_grid as dag
2-
from dash import Dash, html, dcc, Input, Output, State
2+
from dash import Dash, html, dcc, Input, Output, State, Patch
33
import plotly.express as px
44
from . import utils
55
import json
6+
from selenium.webdriver.common.by import By
7+
from dash.testing.wait import until
8+
69

710
df = px.data.medals_wide()
811

@@ -84,3 +87,38 @@ def test_el002_event_listener(dash_duo):
8487
# Test left click.
8588
grid.get_cell(1, 2).click()
8689
assert dash_duo.find_element('#log').text == "rawr"
90+
91+
def test_el003_event_listener(dash_duo):
92+
app = Dash(__name__, suppress_callback_exceptions=True)
93+
app.layout = html.Div([
94+
dag.AgGrid(id='grid',
95+
columnDefs=[{'field': 'test'}],
96+
rowData=[{'test': '1'}],
97+
eventListeners={'cellClicked': ['TestEvent(params, setEventData)']}
98+
),
99+
html.Div(id='output', children=[])
100+
]
101+
)
102+
103+
@app.callback(
104+
Output('output', 'children'),
105+
Input('grid', 'eventData')
106+
)
107+
def show_event_data(v):
108+
children = Patch()
109+
if v:
110+
children.append(html.Div(json.dumps(v)))
111+
return children
112+
113+
dash_duo.start_server(app)
114+
115+
grid = utils.Grid(dash_duo, "grid")
116+
grid.wait_for_cell_text(0, 0, "1")
117+
118+
for i in range(5):
119+
grid.get_cell(0, 0).click()
120+
121+
# Assert that the output element has children
122+
until(lambda: len(dash_duo.find_element("#output").find_elements(By.XPATH, "*")) == (i + 1), timeout=3)
123+
124+

0 commit comments

Comments
 (0)