Skip to content

Commit

Permalink
primefaces#891 Add onEditorSubmit and onEditorCancel callbacks for Co…
Browse files Browse the repository at this point in the history
…ulmn & BodyCell
  • Loading branch information
TonisPiip committed May 17, 2019
1 parent 87869fb commit e17ebad
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 9 deletions.
4 changes: 4 additions & 0 deletions src/components/column/Column.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ export class Column extends Component {
editor: null,
editorValidator: null,
editorValidatorEvent: 'click',
onEditorSubmit: null,
onEditorCancel: null,
excludeGlobalFilter: false,
rowReorder: false,
rowReorderIcon: 'pi pi-bars'
Expand Down Expand Up @@ -73,6 +75,8 @@ export class Column extends Component {
rowSpan: PropTypes.number,
editor: PropTypes.func,
editorValidator: PropTypes.func,
onEditorSubmit: PropTypes.func,
onEditorCancel: PropTypes.func,
editorValidatorEvent: PropTypes.string,
excludeGlobalFilter: PropTypes.bool,
rowReorder: PropTypes.bool,
Expand Down
31 changes: 22 additions & 9 deletions src/components/datatable/BodyCell.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,12 @@ export class BodyCell extends Component {
}

onKeyDown(event) {
if (event.which === 13 || event.which === 9) {
this.switchCellToViewMode();
if (event.which === 13 || event.which === 9) { // tab || enter
this.switchCellToViewMode(true);
}
if (event.which === 27) // escape
{
this.switchCellToViewMode(false);
}
}

Expand All @@ -50,7 +54,7 @@ export class BodyCell extends Component {

onBlur() {
if (this.state.editing && this.props.editorValidatorEvent === 'blur') {
this.switchCellToViewMode();
this.switchCellToViewMode(true);
}
}

Expand All @@ -62,7 +66,7 @@ export class BodyCell extends Component {
if (!this.documentEditListener) {
this.documentEditListener = (event) => {
if (!this.editingCellClick) {
this.switchCellToViewMode();
this.switchCellToViewMode(true);
}

this.editingCellClick = false;
Expand All @@ -81,15 +85,24 @@ export class BodyCell extends Component {

this.unbindDocumentEditListener();
}
switchCellToViewMode() {
if (this.props.editorValidator) {

switchCellToViewMode(submit) {
if (this.props.editorValidator && submit) {
let valid = this.props.editorValidator(this.props);
if (valid) {
if (this.props.onEditorSubmit) {
this.props.onEditorSubmit(this.props)
}
this.closeCell();
}
} // as per previous version if not valid and another editor is open, keep invalid data editor open.
}
else {
if (submit && this.props.onEditorSubmit) {
this.props.onEditorSubmit(this.props)
}
else if (this.props.onEditorCancel) {
this.props.onEditorCancel(this.props);
}
this.closeCell();
}
}
Expand Down Expand Up @@ -118,7 +131,7 @@ export class BodyCell extends Component {
this.keyHelper.removeAttribute('tabindex');
}
}, 50);
}
}
}
}

Expand Down

0 comments on commit e17ebad

Please sign in to comment.