From ac38d2f28eca9bb124ac5039f047d94f0e874906 Mon Sep 17 00:00:00 2001 From: AllenFang Date: Sat, 1 Sep 2018 17:00:34 +0800 Subject: [PATCH 1/2] fix #514 --- .../src/checkbox-editor.js | 10 +++++++--- packages/react-bootstrap-table2-editor/src/context.js | 3 ++- .../react-bootstrap-table2-editor/src/date-editor.js | 11 +++++++---- .../src/dropdown-editor.js | 11 +++++++---- .../react-bootstrap-table2-editor/src/editing-cell.js | 6 +++++- .../react-bootstrap-table2-editor/src/text-editor.js | 11 +++++++---- .../src/textarea-editor.js | 11 +++++++---- 7 files changed, 42 insertions(+), 21 deletions(-) diff --git a/packages/react-bootstrap-table2-editor/src/checkbox-editor.js b/packages/react-bootstrap-table2-editor/src/checkbox-editor.js index 561f25c..51dd12b 100644 --- a/packages/react-bootstrap-table2-editor/src/checkbox-editor.js +++ b/packages/react-bootstrap-table2-editor/src/checkbox-editor.js @@ -13,7 +13,9 @@ class CheckBoxEditor extends Component { } componentDidMount() { + const { didMount } = this.props; this.checkbox.focus(); + if (didMount) didMount(); } getValue() { @@ -28,7 +30,7 @@ class CheckBoxEditor extends Component { } render() { - const { defaultValue, className, ...rest } = this.props; + const { defaultValue, didMount, className, ...rest } = this.props; const editorClass = cs('editor edit-chseckbox checkbox', className); return ( +export default (_, onStartEdit) => class EditingCell extends Component { static propTypes = { row: PropTypes.object.isRequired, @@ -151,6 +151,10 @@ export default _ => onBlur: this.handleBlur }; + if (onStartEdit) { + editorProps.didMount = () => onStartEdit(row, column, rowIndex, columnIndex); + } + const isDefaultEditorDefined = _.isObject(column.editor); if (isDefaultEditorDefined) { diff --git a/packages/react-bootstrap-table2-editor/src/text-editor.js b/packages/react-bootstrap-table2-editor/src/text-editor.js index b44c2da..1a28a29 100644 --- a/packages/react-bootstrap-table2-editor/src/text-editor.js +++ b/packages/react-bootstrap-table2-editor/src/text-editor.js @@ -5,9 +5,10 @@ import PropTypes from 'prop-types'; class TextEditor extends Component { componentDidMount() { - const { defaultValue } = this.props; + const { defaultValue, didMount } = this.props; this.text.value = defaultValue; this.text.focus(); + if (didMount) didMount(); } getValue() { @@ -15,7 +16,7 @@ class TextEditor extends Component { } render() { - const { defaultValue, className, ...rest } = this.props; + const { defaultValue, didMount, className, ...rest } = this.props; const editorClass = cs('form-control editor edit-text', className); return ( Date: Sat, 1 Sep 2018 17:01:10 +0800 Subject: [PATCH 2/2] patch story for add cell.onStartEdit(#514) --- .../examples/cell-edit/cell-edit-hooks-table.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/react-bootstrap-table2-example/examples/cell-edit/cell-edit-hooks-table.js b/packages/react-bootstrap-table2-example/examples/cell-edit/cell-edit-hooks-table.js index afb1523..403dc72 100644 --- a/packages/react-bootstrap-table2-example/examples/cell-edit/cell-edit-hooks-table.js +++ b/packages/react-bootstrap-table2-example/examples/cell-edit/cell-edit-hooks-table.js @@ -41,6 +41,7 @@ const columns = [{ columns={ columns } cellEdit={ cellEditFactory({ mode: 'click', + onStartEdit: (row, column, rowIndex, columnIndex) => { console.log('start to edit!!!'); }, beforeSaveCell: (oldValue, newValue, row, column) => { console.log('Before Saving Cell!!'); }, afterSaveCell: (oldValue, newValue, row, column) => { console.log('After Saving Cell!!'); } }) } @@ -55,6 +56,7 @@ export default () => ( columns={ columns } cellEdit={ cellEditFactory({ mode: 'click', + onStartEdit: (row, column, rowIndex, columnIndex) => { console.log('Start to edit!!!'); }, beforeSaveCell: (oldValue, newValue, row, column) => { console.log('Before Saving Cell!!'); }, afterSaveCell: (oldValue, newValue, row, column) => { console.log('After Saving Cell!!'); } }) }