diff --git a/README.md b/README.md
index 5ecedd4..489c27e 100644
--- a/README.md
+++ b/README.md
@@ -10,7 +10,7 @@ This plugin allows cells within a [DataTable](https://datatables.net/) to be edi
##### Settings { JSON Object }
Property | Type | Default | Example | Details
:------ | :------ | :------ | :-----| :------
-**onUpdate** | function | | ```function(cell, row, oldValue){ } ``` | The call back function to be executed. The updated **[cell](https://datatables.net/reference/api/cell())**, **[row](https://datatables.net/reference/api/row())**, and previous value in that cell are passed as arguments.
+**onUpdate** | function | | ```function(cell, row, oldValue){ } ``` | The call back function to be executed. The updated **[cell](https://datatables.net/reference/api/cell())**, **[row](https://datatables.net/reference/api/row())**, and previous value in that cell are passed as arguments. This function can return a jQuery promise object. In such case, the table will be redraw when the promise is resolved.
**onValidate** _(optional)_ | function | none | ```function(cell, row, newValue){ } ``` | The call back function to be executed before updating the cell value. The relevant **[cell](https://datatables.net/reference/api/cell())**, **[row](https://datatables.net/reference/api/row())**, and new value in the editor are passed as arguments. The function should return `true` if the value is valid, or `false` if it does not pass validation logic.
**inputCss** _(optional)_| string | none |```'my-css-class'```| A CSS class that will be applied to the input field
**wrapperHtml** _(optional)_| string | none |```
{content}
```| HTML used to wrap the inline editor. Use `{content}` as the placeholder for the inline editor.
diff --git a/js/dataTables.cellEdit.js b/js/dataTables.cellEdit.js
index 7b0448b..9684052 100644
--- a/js/dataTables.cellEdit.js
+++ b/js/dataTables.cellEdit.js
@@ -33,6 +33,7 @@ jQuery.fn.dataTable.Api.register('MakeCellsEditable()', function (settings) {
var cell = table.cell($(callingElement).parents('td, th'));
var columnIndex = cell.index().column;
var inputField =getInputField(callingElement);
+ var returnValue;
// Update
var newValue = inputField.val();
@@ -41,7 +42,7 @@ jQuery.fn.dataTable.Api.register('MakeCellsEditable()', function (settings) {
if (settings.allowNulls.columns) {
// If current column allows nulls
if (settings.allowNulls.columns.indexOf(columnIndex) > -1) {
- _update(newValue);
+ returnValue = _update(newValue);
} else {
_addValidationCss();
}
@@ -52,13 +53,13 @@ jQuery.fn.dataTable.Api.register('MakeCellsEditable()', function (settings) {
//All columns allow null
} else if (newValue && settings.onValidate) {
if (settings.onValidate(cell, row, newValue)) {
- _update(newValue);
+ returnValue = _update(newValue);
} else {
_addValidationCss();
}
}
else {
- _update(newValue);
+ returnValue = _update(newValue);
}
function _addValidationCss() {
// Show validation error
@@ -72,13 +73,24 @@ jQuery.fn.dataTable.Api.register('MakeCellsEditable()', function (settings) {
var oldValue = cell.data();
cell.data(newValue);
//Return cell & row.
- settings.onUpdate(cell, row, oldValue);
+ return settings.onUpdate(cell, row, oldValue);
}
- // Get current page
- var currentPageIndex = table.page.info().page;
- //Redraw table
- table.page(currentPageIndex).draw(false);
+ var _lastActions = function(){
+ // Get current page
+ var currentPageIndex = table.page.info().page;
+
+ //Redraw table
+ table.page(currentPageIndex).draw(false);
+ }
+
+ // If returnValue has then method, assume it's a promise
+ if( "object" === typeof returnValue && "function" === typeof returnValue.then ){
+ returnValue.then(function(){
+ _lastActions();
+ });
+ }
+ else _lastActions();
},
// CANCEL
cancelEditableCell: function (callingElement) {