mirror of
https://github.com/Mottie/tablesorter.git
synced 2024-11-15 23:54:22 +00:00
Core: optimize textExtraction function
Reduced comparisons & moved "simple" textExtraction before checks for textExtraction functions & using getColumnData, to further speed up processing time
This commit is contained in:
parent
b3a7b82a67
commit
3213d16867
@ -1555,11 +1555,15 @@ $.extend($.tablesorter.themes.jui, {
|
|||||||
|
|
||||||
<tr id="textextraction">
|
<tr id="textextraction">
|
||||||
<td><a href="#" class="permalink">textExtraction</a></td>
|
<td><a href="#" class="permalink">textExtraction</a></td>
|
||||||
<td>String Or Function</td>
|
<td>Multiple*</td>
|
||||||
<td>"basic"</td>
|
<td>"basic"</td>
|
||||||
<td>Defines which method is used to extract data from a table cell for sorting (<span class="version updated">v2.17.0</span>)
|
<td>Defines which method is used to extract data from a table cell for sorting (<span class="version updated">v2.18.5</span>)
|
||||||
<div class="collapsible">
|
<div class="collapsible">
|
||||||
<br>
|
<br>
|
||||||
|
* <span class="label label-info">Note</span> This option accepts multiple types (String, Object or Function); see below for further details.
|
||||||
|
<p></p>
|
||||||
|
In <span class="version updated">v2.18.5</span>, the code was further optimized. When set to <code>"basic"</code> (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.
|
||||||
|
<p></p>
|
||||||
In <span class="version updated">v2.17.0</span>, the <code>textExtraction</code> column can also be referenced by using a jQuery selector (e.g. class name, id or column index) that points to a table <em>header</em> cell.<br>
|
In <span class="version updated">v2.17.0</span>, the <code>textExtraction</code> column can also be referenced by using a jQuery selector (e.g. class name, id or column index) that points to a table <em>header</em> cell.<br>
|
||||||
<pre class="prettyprint lang-js">textExtraction : {
|
<pre class="prettyprint lang-js">textExtraction : {
|
||||||
// 'jQuery thead cell selector' : function ( new method )
|
// 'jQuery thead cell selector' : function ( new method )
|
||||||
|
@ -180,24 +180,23 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getElementText(table, node, cellIndex) {
|
function getElementText(table, node, cellIndex) {
|
||||||
if (!node) { return ""; }
|
if (!node) { return ''; }
|
||||||
var te, c = table.config,
|
var te,
|
||||||
t = c.textExtraction || '',
|
$node = $(node),
|
||||||
text = "";
|
c = table.config,
|
||||||
if (t === "basic") {
|
t = c.textExtraction || '';
|
||||||
// check data-attribute first
|
if (typeof(t) === 'string') {
|
||||||
text = $(node).attr(c.textAttribute) || node.textContent || node.innerText || $(node).text() || "";
|
// 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 {
|
} else {
|
||||||
if (typeof(t) === "function") {
|
if (typeof(t) === 'function') {
|
||||||
text = t(node, table, cellIndex);
|
return $.trim( t(node, table, cellIndex) );
|
||||||
} else if (typeof (te = ts.getColumnData( table, t, cellIndex )) === 'function') {
|
} else if (typeof (te = ts.getColumnData( table, t, cellIndex )) === 'function') {
|
||||||
text = te(node, table, cellIndex);
|
return $.trim( te(node, table, cellIndex) );
|
||||||
} else {
|
|
||||||
// previous "simple" method
|
|
||||||
text = node.textContent || node.innerText || $(node).text() || "";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return $.trim(text);
|
// fallback
|
||||||
|
return $.trim( node.textContent || $node.text() || '' );
|
||||||
}
|
}
|
||||||
|
|
||||||
function detectParserForColumn(table, rows, rowIndex, cellIndex) {
|
function detectParserForColumn(table, rows, rowIndex, cellIndex) {
|
||||||
|
Loading…
Reference in New Issue
Block a user