diff --git a/src/components/datatable/BodyCell.vue b/src/components/datatable/BodyCell.vue
index d22ed4aef..fe9068547 100644
--- a/src/components/datatable/BodyCell.vue
+++ b/src/components/datatable/BodyCell.vue
@@ -88,7 +88,7 @@ export default {
if (!this.documentEditListener) {
this.documentEditListener = (event) => {
if (this.isOutsideClicked(event)) {
- this.switchCellToViewMode();
+ this.completeEdit(event, 'outside');
}
};
@@ -108,27 +108,39 @@ export default {
isOutsideClicked(event) {
return !this.$el.contains(event.target) && !this.$el.isSameNode(event.target);
},
- onClick() {
+ onClick(event) {
if (this.isEditable() && !this.editing) {
this.editing = true;
-
this.bindDocumentEditListener();
+ this.$emit('edit-init', {originalEvent: event, data: this.rowData, field: this.column.field, index: this.index});
+ }
+ },
+ completeEdit(event, type) {
+ let editEvent = {originalEvent: event, data: this.rowData, field: this.column.field, index: this.index, type: type, preventDefault: () => event.preventDefault()};
+ this.$emit('edit-complete', editEvent);
+
+ if (!event.defaultPrevented) {
+ this.switchCellToViewMode();
}
},
onKeyDown(event) {
switch (event.which) {
case 13:
+ this.completeEdit(event, 'enter');
+ break;
+
case 27:
this.switchCellToViewMode();
+ this.$emit('edit-cancel', {originalEvent: event, data: this.rowData, field: this.column.field, index: this.index});
break;
case 9:
+ this.completeEdit(event, 'tab');
+
if (event.shiftKey)
this.moveToPreviousCell(event);
else
this.moveToNextCell(event);
-
- this.switchCellToViewMode();
break;
}
},
@@ -202,6 +214,9 @@ export default {
else {
return null;
}
+ },
+ isEditingCellValid() {
+ return (DomHandler.find(this.$el, '.p-invalid').length === 0);
}
},
computed: {
diff --git a/src/components/datatable/DataTable.d.ts b/src/components/datatable/DataTable.d.ts
index 556c30533..7a240cea4 100644
--- a/src/components/datatable/DataTable.d.ts
+++ b/src/components/datatable/DataTable.d.ts
@@ -44,6 +44,7 @@ export declare class DataTable extends Vue {
expandedRowGroups?: any[];
stateStorage?: string;
stateKey?: string;
+ editMode?: string;
$emit(eventName: 'page', event: Event): this;
$emit(eventName: 'sort', event: Event): this;
$emit(eventName: 'filter', event: Event): this;
@@ -56,6 +57,9 @@ export declare class DataTable extends Vue {
$emit(eventName: 'row-collapse', event: Event): this;
$emit(eventName: 'rowgroup-expand', event: Event): this;
$emit(eventName: 'rowgroup-collapse', event: Event): this;
+ $emit(eventName: 'edit-init', event: Event): this;
+ $emit(eventName: 'edit-complete', event: Event): this;
+ $emit(eventName: 'edit-cancel', event: Event): this;
$slots: {
header: VNode[];
paginatorLeft: VNode[];
diff --git a/src/components/datatable/DataTable.vue b/src/components/datatable/DataTable.vue
index 856c5cfba..7e1dd6983 100644
--- a/src/components/datatable/DataTable.vue
+++ b/src/components/datatable/DataTable.vue
@@ -71,7 +71,8 @@
Simple editors with v-model.
+Advanced editors with validations and ability to revert values with escape key.
+