Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |```<div class="row">{content}</div>```| HTML used to wrap the inline editor. Use `{content}` as the placeholder for the inline editor.
Expand Down
28 changes: 20 additions & 8 deletions js/dataTables.cellEdit.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();
}
Expand All @@ -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
Expand All @@ -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) {
Expand Down