diff --git a/docs/index.html b/docs/index.html index 7ef30e1d..a9818cc5 100644 --- a/docs/index.html +++ b/docs/index.html @@ -1555,11 +1555,15 @@ $.extend($.tablesorter.themes.jui, {
"basic"
(the default), the textExtraction code will check for data-attributes, otherwise, any other string value setting will skip the data-attribute value check; because of this change, there is a noticable lessening of initialization time in Internet Explorer.
+
In v2.17.0, the textExtraction
column can also be referenced by using a jQuery selector (e.g. class name, id or column index) that points to a table header cell.textExtraction : { // 'jQuery thead cell selector' : function ( new method ) diff --git a/js/jquery.tablesorter.js b/js/jquery.tablesorter.js index 2248a534..8fe18f80 100644 --- a/js/jquery.tablesorter.js +++ b/js/jquery.tablesorter.js @@ -180,24 +180,23 @@ } function getElementText(table, node, cellIndex) { - if (!node) { return ""; } - var te, c = table.config, - t = c.textExtraction || '', - text = ""; - if (t === "basic") { - // check data-attribute first - text = $(node).attr(c.textAttribute) || node.textContent || node.innerText || $(node).text() || ""; + if (!node) { return ''; } + var te, + $node = $(node), + c = table.config, + t = c.textExtraction || ''; + if (typeof(t) === 'string') { + // check data-attribute first when set to "basic"; don't use node.innerText - it's really slow! + return $.trim( (t === 'basic' ? $node.attr(c.textAttribute) || node.textContent : node.textContent ) || $node.text() || '' ); } else { - if (typeof(t) === "function") { - text = t(node, table, cellIndex); + if (typeof(t) === 'function') { + return $.trim( t(node, table, cellIndex) ); } else if (typeof (te = ts.getColumnData( table, t, cellIndex )) === 'function') { - text = te(node, table, cellIndex); - } else { - // previous "simple" method - text = node.textContent || node.innerText || $(node).text() || ""; + return $.trim( te(node, table, cellIndex) ); } } - return $.trim(text); + // fallback + return $.trim( node.textContent || $node.text() || '' ); } function detectParserForColumn(table, rows, rowIndex, cellIndex) {