Skip to content
This repository has been archived by the owner on Oct 4, 2021. It is now read-only.

Commit

Permalink
v0.0.10
Browse files Browse the repository at this point in the history
  • Loading branch information
Mobius1 committed Oct 7, 2017
1 parent c632a1e commit 1efcd57
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 37 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,10 @@ datatable.editable.saveRow(["foo", "bar", "baz", "qux"]);

## Changelog

`v0.0.10`

* Fixed `Enter` key not saving row.

`v0.0.9`

* Change event name:
Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vanilla-datatables-editable",
"version": "0.0.9",
"version": "0.0.10",
"main": "datatable.editable.min.js",
"ignore": [
".gitattributes",
Expand Down
4 changes: 2 additions & 2 deletions datatable.editable.css
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/*! Editable 0.0.9
/*! Editable 0.0.10
* © 2016-2017 Karl Saunders
*/
/**
* @summary Editable
* @description Allow editing of cells and rows
* @version 0.0.9
* @version 0.0.10
* @file datatable.editable.js
* @author Karl Saunders
* @contact [email protected]
Expand Down
76 changes: 48 additions & 28 deletions datatable.editable.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/*! Editable 0.0.9
/*! Editable 0.0.10
* © 2016-2017 Karl Saunders
*/
/**
* @summary Editable
* @description Allow editing of cells and rows
* @version 0.0.9
* @version 0.0.10
* @file datatable.editable.js
* @author Karl Saunders
* @contact [email protected]
Expand Down Expand Up @@ -310,7 +310,11 @@ if (window.DataTable && typeof window.DataTable === "function") {
if (this.editing && this.data) {
if (e.keyCode === 13) {
// Enter key saves
this.saveCell();
if (this.editingCell) {
this.saveCell();
} else if (this.editingRow) {
this.saveRow();
}
} else if (e.keyCode === 27) {
// Escape key reverts
this.saveCell(this.data.content);
Expand Down Expand Up @@ -365,13 +369,15 @@ if (window.DataTable && typeof window.DataTable === "function") {
cell = cell || this.data.cell;
value = value || this.data.input.value;

var oldData = cell.data;

// Set the cell content
cell.innerHTML = value.trim();

this.data = {};
this.editing = this.editingCell = false;

instance.emit("editable.save.cell");
instance.emit("editable.save.cell", value, oldData);
};

/**
Expand All @@ -393,17 +399,17 @@ if (window.DataTable && typeof window.DataTable === "function") {

var template = [
"<div class='" + o.classes.inner + "'>",
"<div class='" + o.classes.header + "'>",
"<h4>Editing row</h4>",
"<button class='" + o.classes.close + "' type='button' data-editor-close>×</button>",
" </div>",
"<div class='" + o.classes.block + "'>",
"<form class='" + o.classes.form + "'>",
"<div class='" + o.classes.row + "'>",
"<button class='" + o.classes.save + "' type='button' data-editor-save>Save</button>",
"</div>",
"</form>",
"</div>",
"<div class='" + o.classes.header + "'>",
"<h4>Editing row</h4>",
"<button class='" + o.classes.close + "' type='button' data-editor-close>×</button>",
" </div>",
"<div class='" + o.classes.block + "'>",
"<form class='" + o.classes.form + "'>",
"<div class='" + o.classes.row + "'>",
"<button class='" + o.classes.save + "' type='button' data-editor-save>Save</button>",
"</div>",
"</form>",
"</div>",
"</div>",
].join("");

Expand All @@ -421,8 +427,8 @@ if (window.DataTable && typeof window.DataTable === "function") {
class: o.classes.row,
html: [
"<div class='datatable-editor-row'>",
"<label class='" + o.classes.label + "'>" + instance.labels[o.hiddenColumns ? i : instance.activeHeadings[i].originalCellIndex] + "</label>",
"<input class='" + o.classes.input + "' value='" + cell.innerHTML + "' type='text'>",
"<label class='" + o.classes.label + "'>" + instance.labels[o.hiddenColumns ? i : instance.activeHeadings[i].originalCellIndex] + "</label>",
"<input class='" + o.classes.input + "' value='" + cell.innerHTML + "' type='text'>",
"</div>"
].join("")
}), form.lastElementChild);
Expand All @@ -432,8 +438,15 @@ if (window.DataTable && typeof window.DataTable === "function") {

this.openModal();

// Grab the inputs
var inputs = [].slice.call(form.elements);

// Remove save button
inputs.pop();

that.data = {
row: row
row: row,
inputs: inputs
};

this.editing = true;
Expand All @@ -445,11 +458,8 @@ if (window.DataTable && typeof window.DataTable === "function") {
if (node.hasAttribute("data-editor-close")) { // close button
that.closeModal();
} else if (node.hasAttribute("data-editor-save")) { // save button
var data = [].slice.call(form.elements).map(function(input) {
return input.value.trim();
});

that.saveRow(data);
// Save
that.saveRow();
}
});

Expand All @@ -466,8 +476,16 @@ if (window.DataTable && typeof window.DataTable === "function") {
var that = this,
o = that.config;

data = data || that.data.inputs.map(function(input) {
return input.value.trim();
});
row = row || that.data.row;

// Store the old data for the emitter
var oldData = [].slice.call(row.cells).map(function(cell) {
return cell.data;
});

[].slice.call(row.cells).forEach(function(cell, i) {
cell = instance.data[row.dataIndex].cells[o.hiddenColumns ? i : instance.activeHeadings[i].originalCellIndex];
cell.innerHTML = cell.data = data[i];
Expand All @@ -477,7 +495,7 @@ if (window.DataTable && typeof window.DataTable === "function") {

this.closeModal();

instance.emit("editable.save.row");
instance.emit("editable.save.row", data, oldData);
};

/**
Expand Down Expand Up @@ -551,15 +569,17 @@ if (window.DataTable && typeof window.DataTable === "function") {
*/
Editor.prototype.dismiss = function(e) {

var valid = true,
editing = this.editing && this.editingCell;
var valid = true;

if (this.config.contextMenu) {
valid = !this.wrapper.contains(e.target) && (editing && e.target !== this.data.input);
valid = !this.wrapper.contains(e.target);
if (this.editing) {
valid = !this.wrapper.contains(e.target) && e.target !== this.data.input;
}
}

if (valid) {
if (editing) {
if (this.editing) {
// Revert
this.saveCell(this.data.content);
}
Expand Down
26 changes: 24 additions & 2 deletions datatable.editable.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 1efcd57

Please sign in to comment.