Skip to content

Commit 8866a69

Browse files
committed
Merge branch 'jspaine-v4.0.0-dev' into v4.0.0-dev
2 parents 9599450 + a864f82 commit 8866a69

File tree

2 files changed

+46
-8
lines changed

2 files changed

+46
-8
lines changed

examples/js/advance/edit-type-table.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/* eslint max-len: 0 */
2+
/* eslint no-console: 0 */
23
import React from 'react';
34
import { BootstrapTable, TableHeaderColumn } from 'react-bootstrap-table';
45

@@ -66,10 +67,17 @@ export default class EditTypeTable extends React.Component {
6667
}
6768

6869
render() {
70+
// custom attributes on editor
71+
const attrs = {
72+
rows: 10,
73+
onKeyDown: function() {
74+
console.log('keydown event trigger');
75+
}
76+
};
6977
return (
7078
<BootstrapTable data={ jobs } cellEdit={ cellEditProp }>
7179
<TableHeaderColumn dataField='id' isKey={ true }>Job ID</TableHeaderColumn>
72-
<TableHeaderColumn dataField='name' editable={ { type: 'textarea' } }>Job Name</TableHeaderColumn>
80+
<TableHeaderColumn dataField='name' editable={ { type: 'textarea', attrs: attrs } }>Job Name</TableHeaderColumn>
7381
<TableHeaderColumn dataField='type1' dataFormat={ this.formatType } editable={ { type: 'select', options: { values: jobTypes } } }>Job Type1</TableHeaderColumn>
7482
<TableHeaderColumn dataField='type2' editable={ { type: 'select', options: { values: this.jobTypes } } }>Job Type2</TableHeaderColumn>
7583
<TableHeaderColumn dataField='active' editable={ { type: 'checkbox', options: { values: 'Y:N' } } }>Active</TableHeaderColumn>

src/TableEditColumn.js

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,8 @@ class TableEditColumn extends Component {
148148
}
149149

150150
focusInEditor() {
151-
if (Util.isFunction(this.refs.inputRef.focus)) {
152-
this.refs.inputRef.focus();
151+
if (this.inputRef && Util.isFunction(this.inputRef.focus)) {
152+
this.inputRef.focus();
153153
}
154154
}
155155

@@ -159,6 +159,29 @@ class TableEditColumn extends Component {
159159
}
160160
}
161161

162+
getInputRef = userRef => ref => {
163+
this.inputRef = ref;
164+
if (Util.isFunction(userRef)) {
165+
userRef(ref);
166+
} else if (typeof userRef === 'string') {
167+
throw new Error('Ref must be a function');
168+
}
169+
}
170+
171+
getHandleKeyPress = customHandler => e => {
172+
this.handleKeyPress(e);
173+
if (Util.isFunction(customHandler)) {
174+
customHandler(e);
175+
}
176+
}
177+
178+
getHandleBlur = customHandler => e => {
179+
this.handleBlur(e);
180+
if (Util.isFunction(customHandler)) {
181+
customHandler(e);
182+
}
183+
}
184+
162185
render() {
163186
const {
164187
editable,
@@ -170,15 +193,22 @@ class TableEditColumn extends Component {
170193
} = this.props;
171194
const { shakeEditor } = this.state;
172195
const attr = {
173-
ref: 'inputRef',
174-
onKeyDown: this.handleKeyPress,
175-
onBlur: this.handleBlur
196+
...editable.attrs,
197+
ref: this.getInputRef(editable.attrs && editable.attrs.ref),
198+
onKeyDown: this.getHandleKeyPress(editable.attrs && editable.attrs.onKeyDown),
199+
onBlur: this.getHandleBlur(editable.attrs && editable.attrs.onBlur)
176200
};
177201
let style = { position: 'relative' };
178202
let { fieldValue } = this.props;
179203
let { className } = this.state;
180-
// put placeholder if exist
181-
editable.placeholder && (attr.placeholder = editable.placeholder);
204+
205+
if (editable.placeholder) {
206+
attr.placeholder = editable.placeholder;
207+
/* eslint-disable no-console */
208+
console.warn(
209+
'Setting editable.placeholder is deprecated. Use editable.attrs to set input attributes');
210+
/* eslint-enable no-console */
211+
}
182212

183213
const editorClass = classSet({ 'animated': shakeEditor, 'shake': shakeEditor });
184214
fieldValue = fieldValue === 0 ? '0' : fieldValue;

0 commit comments

Comments
 (0)