Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow editing responsive columns #100

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
23 changes: 14 additions & 9 deletions js/dataTables.cellEdit.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ jQuery.fn.dataTable.Api.register('MakeCellsEditable()', function (settings) {
updateEditableCell: function (callingElement) {
// Need to redeclare table here for situations where we have more than one datatable on the page. See issue6 on github
var table = $(callingElement).closest("table").DataTable().table();
var row = table.row($(callingElement).parents('tr'));
var cell = table.cell($(callingElement).parents('td, th'));
var row = table.row($(callingElement).parents('tr, li'));
var cell = table.cell($(callingElement).parents('td, th, li'));
var columnIndex = cell.index().column;
var inputField =getInputField(callingElement);

Expand Down Expand Up @@ -83,7 +83,7 @@ jQuery.fn.dataTable.Api.register('MakeCellsEditable()', function (settings) {
// CANCEL
cancelEditableCell: function (callingElement) {
var table = $(callingElement.closest("table")).DataTable().table();
var cell = table.cell($(callingElement).parents('td, th'));
var cell = table.cell($(callingElement).parents('td, th, li'));
// Set cell to it's original value
cell.data(cell.data());

Expand All @@ -94,23 +94,28 @@ jQuery.fn.dataTable.Api.register('MakeCellsEditable()', function (settings) {

// Destroy
if (settings === "destroy") {
$(table.body()).off("click", "td");
$(table.body()).off("click", "td, li");
table = null;
}

if (table != null) {
// On cell click
$(table.body()).on('click', 'td', function () {
$(table.body()).on('click', 'td, li', function () {

var currentColumnIndex = table.cell(this).index().column;
var index = table.cell($(this).closest('td, li')).index();
if (typeof index === 'undefined')
return;
var currentColumnIndex = index.column;

// DETERMINE WHAT COLUMNS CAN BE EDITED
if ((settings.columns && settings.columns.indexOf(currentColumnIndex) > -1) || (!settings.columns)) {
var row = table.row($(this).parents('tr'));
var row = table.row($(this).closest('td, li').parents('tr, li'));
editableCellsRow = row;

var cell = table.cell(this).node();
var oldValue = table.cell(this).data();
var cell = $(this).find('span.dtr-data');
if (cell.length == 0)
cell = table.cell($(this).closest('td, li')).node();
var oldValue = table.cell($(this).closest('td, li')).data();
// Sanitize value
oldValue = sanitizeCellValue(oldValue);

Expand Down