Skip to content

Implement 'TEXTAREA' and 'MULTI-SELECT' in Table Edit. #81

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

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
77 changes: 58 additions & 19 deletions jquery.tabledit.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,28 +120,67 @@ if (typeof jQuery === 'undefined') {

// Create span element.
var span = '<span class="tabledit-span">' + text + '</span>';

// Check if exists the third parameter of editable array.
if (typeof settings.columns.editable[i][2] !== 'undefined') {
// Create select element.
var input = '<select class="tabledit-input ' + settings.inputClass + '" name="' + settings.columns.editable[i][1] + '" style="display: none;" disabled>';

// Create options for select element.
$.each(jQuery.parseJSON(settings.columns.editable[i][2]), function(index, value) {
if (text === value) {
input += '<option value="' + index + '" selected>' + value + '</option>';

// switch the third parameter to test for input type default is text
switch(settings.columns.editable[i][2])
{
//Implement 'TEXTAREA' in tabledit ***Sharad Soni***
case "textarea":
input = '<textarea ';
//each item in 4th object becomes attributes in select
$.each(settings.columns.editable[i][3], function(index, value) {
input += index + '="' + value + '" ';
});
input += 'class="tabledit-input ' + settings.inputClass + '" name="' + settings.columns.editable[i][1] + '" style="display: none;" disabled>' + obj.text() + '</textarea>';
break;

// Implement 'MULTISELECT' in tabledit ***Sharad Soni***
case "multiselect":
// Create select element.
input = '<select class="multiSelect tabledit-input ' + settings.inputClass + '" name="' + settings.columns.editable[i][1] + '" style="display: none; width:auto;" disabled multiple >';

var textArray = '';
if(typeof text == "undefined" || text == "") {
// do nothing
} else {
textArray = text.split(', ');
}

// Create options for select element.
$.each(JSON.parse(settings.columns.editable[i][3]), function(index, value) {
if ($.inArray(value, textArray) > -1) {
input += '<option value="' + index + '" selected>' + value + '</option>';
} else {
input += '<option value="' + index + '">' + value + '</option>';
}
});

// Create last piece of select element.
input += '</select>';
break;

default:
if(settings.columns.editable[i].length <= 2) {
// Create text input element.
input = '<input class="tabledit-input ' + settings.inputClass + '" type="text" name="' + settings.columns.editable[i][1] + '" value="' + obj.text() + '" style="display: none;" disabled>';
break;
} else {
input += '<option value="' + index + '">' + value + '</option>';
// Create select element.
input = '<select class="tabledit-input ' + settings.inputClass + '" name="' + settings.columns.editable[i][1] + '" style="display: none; width:auto;" disabled>';
input += '<option value="">Select</option>';
// Create options for select element.
$.each(JSON.parse(settings.columns.editable[i][2]), function(index, value) {
if (text === value) {
input += '<option value="' + index + '" selected>' + value + '</option>';
} else {
input += '<option value="' + index + '">' + value + '</option>';
}
});

// Create last piece of select element.
input += '</select>';
}
});

// Create last piece of select element.
input += '</select>';
} else {
// Create text input element.
var input = '<input class="tabledit-input ' + settings.inputClass + '" type="text" name="' + settings.columns.editable[i][1] + '" value="' + $(this).text() + '" style="display: none;" disabled>';
}

// Add elements and class "view" to table cell.
$(this).html(span + input);
$(this).addClass('tabledit-view-mode');
Expand Down