Skip to content

Commit 8bb08e2

Browse files
committed
Add support for new Selection API while maintaining backward compatibility with deprecated API, update tests and propCategories.js
1 parent f87c727 commit 8bb08e2

3 files changed

Lines changed: 50 additions & 20 deletions

File tree

src/lib/fragments/AgGrid.react.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,10 @@ export default class DashAgGrid extends Component {
465465
}
466466
if (GRID_NESTED_FUNCTIONS[target]) {
467467
let adjustedVal = value;
468+
if (target === 'rowSelection' && typeof value === 'string') {
469+
// to still support rowSelection='single' | 'multiple' deprecated in v32.3.4
470+
return value
471+
}
468472
if ('suppressCallback' in value) {
469473
adjustedVal = {
470474
...adjustedVal,
@@ -1001,13 +1005,13 @@ export default class DashAgGrid extends Component {
10011005
}
10021006

10031007
onCellValueChanged({
1004-
oldValue,
1005-
value,
1006-
column: {colId},
1007-
rowIndex,
1008-
data,
1009-
node,
1010-
}) {
1008+
oldValue,
1009+
value,
1010+
column: {colId},
1011+
rowIndex,
1012+
data,
1013+
node,
1014+
}) {
10111015
const timestamp = Date.now();
10121016
// Collect new change.
10131017
const newChange = {

src/lib/utils/propCategories.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ export const COLUMN_MAYBE_FUNCTIONS = {
202202
// Columns
203203
keyCreator: 1,
204204
equals: 1,
205+
checkboxSelection: 1,
205206
icons: 1,
206207
suppressNavigable: 1,
207208
suppressKeyboardEvent: 1,
@@ -223,6 +224,7 @@ export const COLUMN_MAYBE_FUNCTIONS = {
223224

224225
// Columns: Headers
225226
suppressHeaderKeyboardEvent: 1,
227+
headerCheckboxSelection: 1,
226228

227229
// Columns: Rendering and Styling
228230
cellStyle: 1,

tests/examples/single_row_selection_remove_checkboxes.py

Lines changed: 37 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
# Test for dag v32.3.4, supporting the new Selection API and still supporting the deprecated Selection API
12
import dash_ag_grid as dag
2-
from dash import Dash
3+
from dash import Dash, html
34
import pandas as pd
45

56
app = Dash()
@@ -10,18 +11,41 @@
1011

1112
columnDefs = [{"field": i} for i in ["country", "year", "athlete", "age", "sport", "total"]]
1213

13-
app.layout = dag.AgGrid(
14-
id="grid-row-selection-remove-checkboxes",
15-
columnDefs=columnDefs,
16-
rowData=df.to_dict("records"),
17-
columnSize="sizeToFit",
18-
dashGridOptions={
19-
"rowSelection": {
20-
'mode': 'singleRow',
21-
# test selection checkboxes as function
22-
'checkboxes': {"function": "params.data.year > 2007"}
23-
},
24-
}
14+
app.layout = html.Div(
15+
[
16+
'New Selection API',
17+
dag.AgGrid(
18+
id="grid-row-selection-remove-checkboxes",
19+
columnDefs=columnDefs,
20+
rowData=df.to_dict("records"),
21+
columnSize="sizeToFit",
22+
dashGridOptions={
23+
"rowSelection": {
24+
'mode': 'singleRow',
25+
# test selection checkboxes as function
26+
'checkboxes': {"function": "params.data.year > 2007"}
27+
},
28+
},
29+
style={'margin-bottom': '10px'},
30+
),
31+
'Deprecated Selection API',
32+
dag.AgGrid(
33+
id="grid-row-selection-remove-checkboxes-deprecated",
34+
columnDefs=columnDefs,
35+
rowData=df.to_dict("records"),
36+
columnSize="sizeToFit",
37+
defaultColDef={
38+
"filter": True,
39+
"checkboxSelection": {
40+
"function": 'params.column == params.api.getAllDisplayedColumns()[0]'
41+
},
42+
"headerCheckboxSelection": {
43+
"function": 'params.column == params.api.getAllDisplayedColumns()[0]'
44+
}
45+
},
46+
dashGridOptions={"rowSelection": "multiple"},
47+
)
48+
]
2549
)
2650

2751
if __name__ == "__main__":

0 commit comments

Comments
 (0)