Skip to content

Commit

Permalink
Merge pull request #573 from SamuelMS/master
Browse files Browse the repository at this point in the history
Core: Add onItemEditCancelling callback
  • Loading branch information
tabalinas committed Jan 1, 2017
2 parents e70b14d + 54bdd85 commit 3e2ac95
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -30,7 +30,7 @@
"grunt-contrib-concat": "~0.3.0",
"grunt-contrib-copy": "^0.7.0",
"grunt-contrib-cssmin": "^0.10.0",
"grunt-contrib-qunit": "^0.5.2",
"grunt-contrib-qunit": "^1.2.0",
"grunt-contrib-uglify": "^0.4.0",
"grunt-image-embed": "^0.3.1",
"grunt-string-replace": "^1.2.1"
Expand Down
11 changes: 11 additions & 0 deletions src/jsgrid.core.js
Expand Up @@ -167,6 +167,7 @@
onItemInserting: $.noop,
onItemInserted: $.noop,
onItemEditing: $.noop,
onItemEditCancelling: $.noop,
onItemUpdating: $.noop,
onItemUpdated: $.noop,
onItemInvalid: $.noop,
Expand Down Expand Up @@ -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;
Expand Down
10 changes: 10 additions & 0 deletions tests/jsgrid.tests.js
Expand Up @@ -1329,6 +1329,8 @@ $(function() {
test("cancel edit", function() {
var $element = $("#jsGrid"),
updated = false,
cancellingArgs,
cancellingRow,
data = [{
field: "value"
}],
Expand All @@ -1351,6 +1353,10 @@ $(function() {
updateData: function(updatingItem) {
updated = true;
}
},
onItemEditCancelling: function(e) {
cancellingArgs = $.extend(true, {}, e);
cancellingRow = grid.rowByItem(data[0])[0];
}
},

Expand All @@ -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");
Expand Down

0 comments on commit 3e2ac95

Please sign in to comment.