diff --git a/README.md b/README.md index d007b9b6..8c46c1dd 100644 --- a/README.md +++ b/README.md @@ -128,6 +128,8 @@ The config object may contain following options (default values are specified be confirmDeleting: true, deleteConfirm: "Are you sure?", + confirmationPopupProvider: null, + pagerContainer: null, pageIndex: 1, pageSize: 20, @@ -341,6 +343,28 @@ A boolean value specifying whether to ask user to confirm item deletion. A string or a function returning string specifying delete confirmation message to be displayed to the user. A function has the signature `function(item)` and accepts item to be deleted. +### confirmationPopupProvider (default `null`) +A function handling confirmation request. Accepts two arguments: message and action callback. +Example: + +```javascript + +$("#grid").jsGrid({ + ... + + confirmationPopupProvider: function (message, callback) { + if (window.confirm(message)) { + if (window.confirm('Are you really sure?')) { + callback(); + } + } + }, + + ... +}); + +``` + ### pagerContainer (default `null`) A jQueryElement or DomNode to specify where to render a pager. Used for external pager rendering. When it is equal to `null`, the pager is rendered at the bottom of the grid. diff --git a/src/jsgrid.core.js b/src/jsgrid.core.js index 1bf2c655..0c3cade4 100755 --- a/src/jsgrid.core.js +++ b/src/jsgrid.core.js @@ -90,6 +90,8 @@ confirmDeleting: true, deleteConfirm: "Are you sure?", + confirmationPopupProvider: null, + selecting: true, selectedRowClass: "jsgrid-selected-row", oddRowClass: "jsgrid-row", @@ -1314,8 +1316,22 @@ if(!$row.length) return; - if(this.confirmDeleting && !window.confirm(getOrApply(this.deleteConfirm, this, $row.data(JSGRID_ROW_DATA_KEY)))) - return; + if (this.confirmDeleting) { + var message = getOrApply(this.deleteConfirm, this, $row.data(JSGRID_ROW_DATA_KEY)); + var self = this; + + if (this.confirmationPopupProvider) { + this.confirmationPopupProvider(message, function () { + self._deleteRow($row); + }); + + return; + } else { + if (!window.confirm(message)) { + return; + } + } + } return this._deleteRow($row); },