Skip to content

Commit

Permalink
Text inputs now appear with the old cell valu in them for easier editing
Browse files Browse the repository at this point in the history
  • Loading branch information
ejbeaty committed May 24, 2016
1 parent cd00e20 commit 71fbb82
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions js/dataTables.cellEdit.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,11 @@ jQuery.fn.dataTable.Api.register('MakeCellsEditable()', function (settings) {
editableCellsRow = row;

var cell = table.cell(this).node();

var oldValue = table.cell(this).data();
// Show input
if (!$(cell).find('input').length && !$(cell).find('select').length) {
// Input CSS
var input = getInputHtml(currentColumnIndex, settings);
var input = getInputHtml(currentColumnIndex, settings,oldValue);
$(cell).html(input.html);
if (input.focus) {
$('#ejbeatycelledit').focus();
Expand All @@ -108,7 +108,7 @@ jQuery.fn.dataTable.Api.register('MakeCellsEditable()', function (settings) {
});
});

function getInputHtml(currentColumnIndex, settings) {
function getInputHtml(currentColumnIndex, settings, oldValue) {
var inputSetting, inputType, input, inputCss, confirmCss, cancelCss;

input = {"focus":true,"html":null}
Expand Down Expand Up @@ -144,13 +144,13 @@ function getInputHtml(currentColumnIndex, settings) {
input.focus = false;
break;
case "text-confirm": // text input w/ confirm
input.html = "<input id='ejbeatycelledit' class='" + inputCss + "'></input>&nbsp;<a href='#' class='" + confirmCss + "' onclick='$(this).updateEditableCell(this)'>Confirm</a> <a href='#' class='" + cancelCss + "' onclick='$(this).cancelEditableCell(this)'>Cancel</a> ";
input.html = "<input id='ejbeatycelledit' class='" + inputCss + "' value='"+oldValue+"'></input>&nbsp;<a href='#' class='" + confirmCss + "' onclick='$(this).updateEditableCell(this)'>Confirm</a> <a href='#' class='" + cancelCss + "' onclick='$(this).cancelEditableCell(this)'>Cancel</a> ";
break;
case "undefined-confirm": // text input w/ confirm
input.html = "<input id='ejbeatycelledit' class='" + inputCss + "'></input>&nbsp;<a href='#' class='" + confirmCss + "' onclick='$(this).updateEditableCell(this)'>Confirm</a> <a href='#' class='" + cancelCss + "' onclick='$(this).cancelEditableCell(this)'>Cancel</a> ";
input.html = "<input id='ejbeatycelledit' class='" + inputCss + "' value='" + oldValue + "'></input>&nbsp;<a href='#' class='" + confirmCss + "' onclick='$(this).updateEditableCell(this)'>Confirm</a> <a href='#' class='" + cancelCss + "' onclick='$(this).cancelEditableCell(this)'>Cancel</a> ";
break;
default: // text input
input.html = "<input id='ejbeatycelledit' class='" + inputCss + "' onfocusout='$(this).updateEditableCell(this)'></input>";
input.html = "<input id='ejbeatycelledit' class='" + inputCss + "' onfocusout='$(this).updateEditableCell(this)' value='" + oldValue + "'></input>";
break;
}
return input;
Expand Down

0 comments on commit 71fbb82

Please sign in to comment.