Permalink
Browse files

Add new pre-item edit cancel event.

- Add onItemEditCancelling event, tests.
- Update README with new event; also added onItemEditing to callback
list, which was actually missing.
  • Loading branch information...
1 parent e70b14d commit 7dd678e7be9651402474de7608ec765ad16fc1bb @SamuelMS SamuelMS committed Dec 31, 2016
Showing with 70 additions and 18 deletions.
  1. +36 −16 README.md
  2. +11 −0 dist/jsgrid.js
  3. +2 −2 dist/jsgrid.min.js
  4. +11 −0 src/jsgrid.core.js
  5. +10 −0 tests/jsgrid.tests.js
View
@@ -1140,28 +1140,30 @@ The following callbacks are supported:
```javascript
{
- onDataLoading: function(args) {}, // before controller.loadData
- onDataLoaded: function(args) {}, // on done of controller.loadData
+ onDataLoading: function(args) {}, // before controller.loadData
+ onDataLoaded: function(args) {}, // on done of controller.loadData
- onInit: function(args) {}, // after grid initialization
+ onInit: function(args) {}, // after grid initialization
- onItemInserting: function(args) {}, // before controller.insertItem
- onItemInserted: function(args) {}, // on done of controller.insertItem
- onItemUpdating: function(args) {}, // before controller.updateItem
- onItemUpdated: function(args) {}, // on done of controller.updateItem
- onItemDeleting: function(args) {}, // before controller.deleteItem
- onItemDeleted: function(args) {}, // on done of controller.deleteItem
- onItemInvalid: function(args) {}, // after item validation, in case data is invalid
+ onItemInserting: function(args) {}, // before controller.insertItem
+ onItemInserted: function(args) {}, // on done of controller.insertItem
+ onItemUpdating: function(args) {}, // before controller.updateItem
+ onItemUpdated: function(args) {}, // on done of controller.updateItem
+ onItemDeleting: function(args) {}, // before controller.deleteItem
+ onItemDeleted: function(args) {}, // on done of controller.deleteItem
+ onItemEditing: function(args) {}, // before item editing
+ onItemEditCancelling: function(args) {}, // before item edit is cancelled
+ onItemInvalid: function(args) {}, // after item validation, in case data is invalid
- onError: function(args) {}, // on fail of any controller call
+ onError: function(args) {}, // on fail of any controller call
- onOptionChanging: function(args) {}, // before changing the grid option
- onOptionChanged: function(args) {}, // after changing the grid option
+ onOptionChanging: function(args) {}, // before changing the grid option
+ onOptionChanged: function(args) {}, // after changing the grid option
- onPageChanged: function(args) {}, // after changing the current page
+ onPageChanged: function(args) {}, // after changing the current page
- onRefreshing: function(args) {}, // before grid refresh
- onRefreshed: function(args) {}, // after grid refresh
+ onRefreshing: function(args) {}, // before grid refresh
+ onRefreshed: function(args) {}, // after grid refresh
}
```
@@ -1368,6 +1370,24 @@ $("#grid").jsGrid({
```
+### onItemEditCancelling
+> version added: 1.5.4
+
+Fires before item edit is cancelled.
+
+Has the following arguments:
+
+```javascript
+
+{
+ grid // grid instance
+ row // editing row jQuery element
+ item // editing item
+ itemIndex // editing item index
+}
+
+```
+
### onItemInserting
Fires before item insertion.
View
@@ -173,6 +173,7 @@
onItemInserting: $.noop,
onItemInserted: $.noop,
onItemEditing: $.noop,
+ onItemEditCancelling: $.noop,
onItemUpdating: $.noop,
onItemUpdated: $.noop,
onItemInvalid: $.noop,
@@ -1347,6 +1348,16 @@
if(!this._editingRow)
return;
+ var $row = this._editingRow,
+ editingItem = $row.data(JSGRID_ROW_DATA_KEY),
+ editingItemIndex = this._itemIndex(editingItem);
+
+ this._callEventHandler(this.onItemEditCancelling, {
+ row: $row,
+ item: editingItem,
+ itemIndex: editingItemIndex
+ });
+
this._getEditRow().remove();
this._editingRow.show();
this._editingRow = null;
View
Oops, something went wrong.
View
@@ -167,6 +167,7 @@
onItemInserting: $.noop,
onItemInserted: $.noop,
onItemEditing: $.noop,
+ onItemEditCancelling: $.noop,
onItemUpdating: $.noop,
onItemUpdated: $.noop,
onItemInvalid: $.noop,
@@ -1341,6 +1342,16 @@
if(!this._editingRow)
return;
+ var $row = this._editingRow,
+ editingItem = $row.data(JSGRID_ROW_DATA_KEY),
+ editingItemIndex = this._itemIndex(editingItem);
+
+ this._callEventHandler(this.onItemEditCancelling, {
+ row: $row,
+ item: editingItem,
+ itemIndex: editingItemIndex
+ });
+
this._getEditRow().remove();
this._editingRow.show();
this._editingRow = null;
View
@@ -1329,6 +1329,8 @@ $(function() {
test("cancel edit", function() {
var $element = $("#jsGrid"),
updated = false,
+ cancellingArgs,
+ cancellingRow,
data = [{
field: "value"
}],
@@ -1351,6 +1353,10 @@ $(function() {
updateData: function(updatingItem) {
updated = true;
}
+ },
+ onItemEditCancelling: function(e) {
+ cancellingArgs = $.extend(true, {}, e);
+ cancellingRow = grid.rowByItem(data[0])[0];
}
},
@@ -1362,6 +1368,10 @@ $(function() {
grid.fields[0].editControl.val("new value");
grid.cancelEdit();
+ deepEqual(cancellingArgs.item, { field: "value" }, "item before cancel is provided in cancelling event args");
+ equal(cancellingArgs.itemIndex, 0, "itemIndex is provided in cancelling event args");
+ equal(cancellingArgs.row[0], cancellingRow, "row element is provided in cancelling event args");
+
ok(!updated, "controller updateItem was not called");
deepEqual(grid.option("data")[0], { field: "value" }, "data were not updated");
equal(grid._content.find("." + grid.editRowClass).length, 0, "edit row removed");

0 comments on commit 7dd678e

Please sign in to comment.