Skip to content

Commit b162b52

Browse files
committed
Updating Custom Cell Editing - matching interface of custom filters
- Need to pass in a factory method and custom properties
1 parent 97e8007 commit b162b52

File tree

2 files changed

+18
-9
lines changed

2 files changed

+18
-9
lines changed

examples/js/cell-edit/custom-cell-edit-table.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ class PriceEditor extends React.Component {
5050
<span>
5151
<input
5252
ref='inputRef'
53-
{ ...this.props }
5453
className={ ( this.props.editorClass || '') + ' form-control editor edit-text' }
5554
style={ { display: 'inline', width: '50%' } }
5655
type='text'
@@ -122,6 +121,9 @@ function priceFormatter(cell, row) {
122121

123122
const regionsFormatter = (cell, row) => (<span>{ (cell || []).join(',') }</span>);
124123

124+
const createPriceEditor = (onUpdate, props) => (<PriceEditor onUpdate={ onUpdate } {...props}/>);
125+
const createRegionsEditor = (onUpdate, props) => (<RegionsEditor onUpdate={ onUpdate } {...props}/>);
126+
125127
export default class CustomCellEditTable extends React.Component {
126128
render() {
127129
return (
@@ -131,13 +133,13 @@ export default class CustomCellEditTable extends React.Component {
131133
<TableHeaderColumn
132134
dataField='price'
133135
dataFormat={ priceFormatter }
134-
customEditor={ PriceEditor }>
136+
customEditor={ { getElement: createPriceEditor, customEditorParameters: { currencies: currencies } } }>
135137
Product Price
136138
</TableHeaderColumn>
137139
<TableHeaderColumn
138140
dataField='regions'
139141
dataFormat={ regionsFormatter }
140-
customEditor={ RegionsEditor }>
142+
customEditor={ { getElement: createRegionsEditor } }>
141143
Regions
142144
</TableHeaderColumn>
143145
</BootstrapTable>

src/TableEditColumn.js

+13-6
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,18 @@ class TableEditColumn extends Component {
9797
editable.placeholder && (attr.placeholder = editable.placeholder);
9898

9999
const editorClass = classSet({ 'animated': shakeEditor, 'shake': shakeEditor });
100-
const CustomEditor = customEditor;
101-
const cellEditor = CustomEditor ? <CustomEditor
102-
{...attr}
103-
defaultValue={ fieldValue || '' }
104-
onUpdate={ this.handleCustomUpdate }/> :
105-
editor(editable, attr, format, editorClass, fieldValue || '');
100+
let cellEditor;
101+
if (customEditor) {
102+
const customEditorProps = {
103+
...attr,
104+
defaultValue: fieldValue || '',
105+
...customEditor.customEditorParameters
106+
};
107+
cellEditor = customEditor.getElement(this.handleCustomUpdate, customEditorProps);
108+
} else {
109+
cellEditor = editor(editable, attr, format, editorClass, fieldValue || '');
110+
}
111+
106112
return (
107113
<td ref='td' style={ { position: 'relative' } }>
108114
{ cellEditor }
@@ -130,6 +136,7 @@ TableEditColumn.propTypes = {
130136
PropTypes.string,
131137
PropTypes.bool,
132138
PropTypes.number,
139+
PropTypes.array,
133140
PropTypes.object
134141
])
135142
};

0 commit comments

Comments
 (0)