mirror of
https://github.com/Mottie/tablesorter.git
synced 2025-01-12 15:24:21 +00:00
Core: After init, computeColumnIndex adds "data-column" to mismatch indexes
This only occurs when the function is called externally and a `config` parameter is passed to the function, otherwise a "data-column" attribute is added to all cells. This change will minimize DOM manipulation.
This commit is contained in:
parent
f6012b4e76
commit
a9ec53ee19
@ -7089,14 +7089,18 @@ $.tablesorter.isDigit( "(2,345.67)" );</pre>
|
||||
|
||||
<tr id="function-computecolumnindex">
|
||||
<td><a href="#" class="permalink">computeColumnIndex</a></td>
|
||||
<td>Adds the correct <code>data-column</code> indexing to all rows passed to this function (<span class="version">v2.16</span>).
|
||||
<div class="collapsible"><br>
|
||||
<td>Adds the correct <code>data-column</code> indexing to all rows passed to this function (<span class="version">v2.16</span>; <span class="version updated">v2.24.7</span>).
|
||||
<div class="collapsible">
|
||||
<p>In <span class="version">v2.24.7</span>, if a <code>config</code> parameter is included, this function will only add a "data-column" attribute to cells where their internal <code>cellIndex</code> doesn't match its actual column index. This does not apply to internal usage where a "data-column" attribute is set on all header & footer cells.</p>
|
||||
Use it as follows:
|
||||
<pre class="prettyprint lang-js">$.tablesorter.computeColumnIndex($rows);</pre>
|
||||
<pre class="prettyprint lang-js">// In v2.24.7, if a config parameter is included "data-columns" are not added
|
||||
// to cells where their cellIndex and calculated column index match
|
||||
$.tablesorter.computeColumnIndex($rows, config);</pre>
|
||||
<ul>
|
||||
<li><code>$rows</code> - jQuery object of rows in which to add data-column indexes</li>
|
||||
<li><code>$rows</code> - jQuery object of rows in which to add data-column indexes.</li>
|
||||
<li><code>config</code> - this is the <code>table.config</code> (table configuration variables) object.</li>
|
||||
</ul>
|
||||
Example result:<pre class="prettyprint lang-html"><tr>
|
||||
Example result (without including <code>config</code>):<pre class="prettyprint lang-html"><tr>
|
||||
<td colspan="2" data-column="0">r0c0</td>
|
||||
<td data-column="2">r0c2</td>
|
||||
</tr>
|
||||
@ -7104,6 +7108,15 @@ $.tablesorter.isDigit( "(2,345.67)" );</pre>
|
||||
<td data-column="0">r1c0</td>
|
||||
<td data-column="1">r1c1</td>
|
||||
<td data-column="2">r1c2</td>
|
||||
</tr></pre>
|
||||
Example result (including <code>config</code>):<pre class="prettyprint lang-html"><tr>
|
||||
<td colspan="2">r0c0</td> <!-- data-column="0" is not included because it matches the cellIndex property -->
|
||||
<td data-column="2">r0c2</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>r1c0</td>
|
||||
<td>r1c1</td>
|
||||
<td>r1c2</td>
|
||||
</tr></pre>
|
||||
</div>
|
||||
</td>
|
||||
|
@ -520,6 +520,7 @@
|
||||
timer = new Date();
|
||||
}
|
||||
// children tr in tfoot - see issue #196 & #547
|
||||
// don't pass table.config to computeColumnIndex here - widgets (math) pass it to "quickly" index tbody cells
|
||||
c.columns = ts.computeColumnIndex( c.$table.children( 'thead, tfoot' ).children( 'tr' ) );
|
||||
// add icon if cssIcon option exists
|
||||
icon = c.cssIcon ?
|
||||
@ -2088,17 +2089,17 @@
|
||||
// computeTableHeaderCellIndexes from:
|
||||
// http://www.javascripttoolbox.com/lib/table/examples.php
|
||||
// http://www.javascripttoolbox.com/temp/table_cellindex.html
|
||||
computeColumnIndex : function( $rows ) {
|
||||
var i, j, k, l, $cell, cell, cells, rowIndex, cellId, rowSpan, colSpan, firstAvailCol,
|
||||
computeColumnIndex : function( $rows, c ) {
|
||||
var i, j, k, l, cell, cells, rowIndex, rowSpan, colSpan, firstAvailCol,
|
||||
// total columns has been calculated, use it to set the matrixrow
|
||||
columns = c && c.columns || 0,
|
||||
matrix = [],
|
||||
matrixrow = [];
|
||||
matrixrow = new Array( columns );
|
||||
for ( i = 0; i < $rows.length; i++ ) {
|
||||
cells = $rows[ i ].cells;
|
||||
for ( j = 0; j < cells.length; j++ ) {
|
||||
cell = cells[ j ];
|
||||
$cell = $( cell );
|
||||
rowIndex = cell.parentNode.rowIndex;
|
||||
cellId = rowIndex + '-' + $cell.index();
|
||||
rowSpan = cell.rowSpan || 1;
|
||||
colSpan = cell.colSpan || 1;
|
||||
if ( typeof matrix[ rowIndex ] === 'undefined' ) {
|
||||
@ -2111,11 +2112,14 @@
|
||||
break;
|
||||
}
|
||||
}
|
||||
// add data-column (setAttribute = IE8+)
|
||||
if ( cell.setAttribute ) {
|
||||
if ( columns && cell.cellIndex === firstAvailCol ) {
|
||||
// don't to anything
|
||||
} else if ( cell.setAttribute ) {
|
||||
// add data-column (setAttribute = IE8+)
|
||||
cell.setAttribute( 'data-column', firstAvailCol );
|
||||
} else {
|
||||
$cell.attr( 'data-column', firstAvailCol );
|
||||
// remove once we drop support for IE7 - 1/12/2016
|
||||
$( cell ).attr( 'data-column', firstAvailCol );
|
||||
}
|
||||
for ( k = rowIndex; k < rowIndex + rowSpan; k++ ) {
|
||||
if ( typeof matrix[ k ] === 'undefined' ) {
|
||||
|
Loading…
Reference in New Issue
Block a user