editable_columns now accepts a range string. Fixes #435

This commit is contained in:
Mottie 2013-11-25 06:20:12 -06:00
parent adda82fbf0
commit 53ec8ae791
2 changed files with 22 additions and 6 deletions

View File

@ -35,7 +35,7 @@ td.no-edit, span.no-edit {
widgets: ['editable'],
widgetOptions: {
editable_columns : [0,1,2], // point to the columns to make editable (zero-based index)
editable_columns : [0,1,2], // or "0-2" (v2.14.2); point to the columns to make editable (zero-based index)
editable_enterToAccept : true, // press enter to accept content, or click outside if false
editable_autoResort : false, // auto resort after the content has changed.
editable_noEdit : 'no-edit', // class name of cell that is not editable
@ -78,7 +78,12 @@ td.no-edit, span.no-edit {
<li>In some browsers, additional CSS is needed to highlight a focused editable table cell. See the CSS block below.</li>
<li>Editable widget options include (defaults in parenthesis):
<ul>
<li><code>editable_column</code> (<code>[]</code>) - Contains an array of columns numbers you want to have editable content (zero-based index). <code>contenteditable="true"</code> is added to cells within these columns.</li>
<li><code>editable_column</code> (<code>[]</code>)
<ul>
<li>In tablesorter core <span class="version">v2.14.2</span>, this widget was updated to allow passing a range string in this option, i.e. <code>"0-2"</code> instead of <code>[0,1,2]</code>.</li>
<li>Contains an array of columns numbers you want to have editable content (zero-based index). <code>contenteditable="true"</code> is added to cells within these columns.</li>
</ul>
</li>
<li><code>editable_enterToAccept</code> (<code>true</code>) - Makes the user press enter to accept the content within the editable table cell; if <code>false</code>, clicking outside the cell will accept the content.</li>
<li><code>editable_autoResort</code> (<code>false</code>) - If <code>true</code> the column will resort (only if already sorted) after the content has been changed.</li>
<li><code>editable_noEdit</code> (<code>'no-edit'</code>) - Class name on table cells to search for that are not to become editable. The search is only done within the columns set by the <code>editable_column</code> option.</li>

View File

@ -18,10 +18,21 @@
},
init: function(table, thisWidget, c, wo){
if (!wo.editable_columns.length) { return; }
var $t, cols = [];
$.each(wo.editable_columns, function(i, col){
cols.push('td:nth-child(' + (col + 1) + ')');
});
var indx, tmp, $t, cols = [];
if (wo.editable_columns.indexOf('-') >= 0) {
// editable_columns can contain a range string (i.e. "2-4" )
tmp = wo.editable_columns.split('-');
indx = parseInt(tmp[0],10) || 0;
tmp = parseInt(tmp[1],10) || (c.columns - 1);
if (tmp > c.columns) { tmp = c.columns - 1; }
for (; indx <= tmp; indx++) {
cols.push('td:nth-child(' + (indx + 1) + ')');
}
} else if ($.isArray(wo.editable_columns)) {
$.each(wo.editable_columns, function(i, col){
cols.push('td:nth-child(' + (col + 1) + ')');
});
}
// IE does not allow making TR/TH/TD cells directly editable (issue #404)
// so add a div or span inside ( it's faster than using wrapInner() )
c.$tbodies.find( cols.join(',') ).not('.' + wo.editable_noEdit).each(function(){