Skip to content

Commit

Permalink
Fixed #589 - Add onBeforeEditorShow and onBeforeEditorHide callbacks …
Browse files Browse the repository at this point in the history
…to Column on DataTable with cell editing
  • Loading branch information
mertsincan committed Mar 5, 2021
1 parent 191d780 commit 4c57968
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/components/column/Column.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ interface ColumnProps {
filterFunction?(value: any, filter: any): void;
editor?(props: any): JSX.Element | undefined;
editorValidator?(e: {originalEvent: Event, columnProps: any}): boolean;
onBeforeEditorHide?(e: {originalEvent: Event, columnProps: any}): any;
onBeforeEditorShow?(e: {originalEvent: Event, columnProps: any}): any;
}

export class Column extends React.Component<ColumnProps,any> {}
6 changes: 5 additions & 1 deletion src/components/column/Column.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ export class Column extends Component {
editor: null,
editorValidator: null,
editorValidatorEvent: 'click',
onBeforeEditorHide: null,
onBeforeEditorShow: null,
onEditorInit: null,
onEditorSubmit: null,
onEditorCancel: null,
Expand Down Expand Up @@ -85,10 +87,12 @@ export class Column extends Component {
rowSpan: PropTypes.number,
editor: PropTypes.func,
editorValidator: PropTypes.func,
editorValidatorEvent: PropTypes.string,
onBeforeEditorHide: null,
onBeforeEditorShow: null,
onEditorInit: PropTypes.func,
onEditorSubmit: PropTypes.func,
onEditorCancel: PropTypes.func,
editorValidatorEvent: PropTypes.string,
excludeGlobalFilter: PropTypes.bool,
rowReorder: PropTypes.bool,
rowReorderIcon: PropTypes.string,
Expand Down
18 changes: 16 additions & 2 deletions src/components/datatable/BodyCell.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ export class BodyCell extends Component {
if (this.props.editMode !== 'row' && this.props.editor && !this.state.editing) {
this.selfClick = true;

if (this.props.onBeforeEditorShow) {
this.props.onBeforeEditorShow({
originalEvent: event,
columnProps: this.props
});
}

this.setState({
editing: true
}, () => {
Expand Down Expand Up @@ -104,7 +111,14 @@ export class BodyCell extends Component {
return this.container && !(this.container.isSameNode(target) || this.container.contains(target));
}

closeCell() {
closeCell(event) {
if (this.props.onBeforeEditorHide) {
this.props.onBeforeEditorHide({
originalEvent: event,
columnProps: this.props
});
}

/* When using the 'tab' key, the focus event of the next cell is not called in IE. */
setTimeout(() => {
this.setState({
Expand Down Expand Up @@ -136,7 +150,7 @@ export class BodyCell extends Component {
this.props.onEditorSubmit(params);
}

this.closeCell();
this.closeCell(event);
}
}

Expand Down
12 changes: 12 additions & 0 deletions src/showcase/datatable/DataTableDoc.js
Original file line number Diff line number Diff line change
Expand Up @@ -1167,6 +1167,18 @@ export const DataTableDemo = () => {
<td>click</td>
<td>Event to trigger the validation, possible values are "click" and "blur".</td>
</tr>
<tr>
<td>onBeforeEditorShow</td>
<td>function</td>
<td>null</td>
<td>Callback to invoke before the cell editor is shown.</td>
</tr>
<tr>
<td>onBeforeEditorHide</td>
<td>function</td>
<td>null</td>
<td>Callback to invoke before the cell editor is hidden.</td>
</tr>
<tr>
<td>onEditorInit</td>
<td>function</td>
Expand Down

0 comments on commit 4c57968

Please sign in to comment.