Skip to content

Commit 856e63d

Browse files
committed
fix #1027
1 parent 423769c commit 856e63d

4 files changed

Lines changed: 53 additions & 36 deletions

File tree

packages/react-bootstrap-table2-editor/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ const columns = [
140140
text: 'Job Type',
141141
editor: {
142142
type: Type.SELECT,
143-
getOptions: () => [.....]
143+
getOptions: (setOptions, { row, column }) => [.....]
144144
}
145145
}];
146146

@@ -152,7 +152,7 @@ const columns = [
152152
text: 'Job Type',
153153
editor: {
154154
type: Type.SELECT,
155-
getOptions: (setOptions) => {
155+
getOptions: (setOptions, { row, column }) => {
156156
setTimeout(() => setOptions([...]), 1500);
157157
}
158158
}

packages/react-bootstrap-table2-editor/src/dropdown-editor.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,13 @@ class DropDownEditor extends Component {
88
super(props);
99
let options = props.options;
1010
if (props.getOptions) {
11-
options = props.getOptions(this.setOptions.bind(this)) || [];
11+
options = props.getOptions(
12+
this.setOptions.bind(this),
13+
{
14+
row: props.row,
15+
column: props.column
16+
}
17+
) || [];
1218
}
1319
this.state = { options };
1420
}
@@ -54,6 +60,8 @@ class DropDownEditor extends Component {
5460
}
5561

5662
DropDownEditor.propTypes = {
63+
row: PropTypes.object.isRequired,
64+
column: PropTypes.object.isRequired,
5765
defaultValue: PropTypes.oneOfType([
5866
PropTypes.string,
5967
PropTypes.number

packages/react-bootstrap-table2-editor/src/editing-cell.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ export default (_, onStartEdit) =>
201201
if (_.isFunction(column.editorRenderer)) {
202202
editor = column.editorRenderer(editorProps, value, row, column, rowIndex, columnIndex);
203203
} else if (isDefaultEditorDefined && column.editor.type === EDITTYPE.SELECT) {
204-
editor = <DropdownEditor { ...editorProps } />;
204+
editor = <DropdownEditor { ...editorProps } row={ row } column={ column } />;
205205
} else if (isDefaultEditorDefined && column.editor.type === EDITTYPE.TEXTAREA) {
206206
editor = <TextAreaEditor { ...editorProps } autoSelectText={ autoSelectText } />;
207207
} else if (isDefaultEditorDefined && column.editor.type === EDITTYPE.CHECKBOX) {

packages/react-bootstrap-table2-example/examples/cell-edit/dropdown-editor-with-dynamic-options-table.js

Lines changed: 41 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint no-console: 0 */
12
/* eslint react/prefer-stateless-function: 0 */
23
import React from 'react';
34

@@ -25,22 +26,26 @@ const columns = [{
2526
text: 'Job Type1',
2627
editor: {
2728
type: Type.SELECT,
28-
getOptions: () => [{
29-
value: 'A',
30-
label: 'A'
31-
}, {
32-
value: 'B',
33-
label: 'B'
34-
}, {
35-
value: 'C',
36-
label: 'C'
37-
}, {
38-
value: 'D',
39-
label: 'D'
40-
}, {
41-
value: 'E',
42-
label: 'E'
43-
}]
29+
getOptions: (setOptions, { row, column }) => {
30+
console.log(`current editing row id: ${row.id}`);
31+
console.log(`current editing column: ${column.dataField}`);
32+
return [{
33+
value: 'A',
34+
label: 'A'
35+
}, {
36+
value: 'B',
37+
label: 'B'
38+
}, {
39+
value: 'C',
40+
label: 'C'
41+
}, {
42+
value: 'D',
43+
label: 'D'
44+
}, {
45+
value: 'E',
46+
label: 'E'
47+
}];
48+
}
4449
}
4550
}, {
4651
dataField: 'type2',
@@ -88,22 +93,26 @@ const columns = [{
8893
text: 'Job Type1',
8994
editor: {
9095
type: Type.SELECT,
91-
getOptions: () => [{
92-
value: 'A',
93-
label: 'A'
94-
}, {
95-
value: 'B',
96-
label: 'B'
97-
}, {
98-
value: 'C',
99-
label: 'C'
100-
}, {
101-
value: 'D',
102-
label: 'D'
103-
}, {
104-
value: 'E',
105-
label: 'E'
106-
}]
96+
getOptions: (setOptions, { row, column }) => {
97+
console.log(\`current editing row id: $\{row.id}\`);
98+
console.log(\`current editing column: $\{column.dataField}\`);
99+
return [{
100+
value: 'A',
101+
label: 'A'
102+
}, {
103+
value: 'B',
104+
label: 'B'
105+
}, {
106+
value: 'C',
107+
label: 'C'
108+
}, {
109+
value: 'D',
110+
label: 'D'
111+
}, {
112+
value: 'E',
113+
label: 'E'
114+
}];
115+
}
107116
}
108117
}, {
109118
dataField: 'type2',

0 commit comments

Comments
 (0)