Core: a column can now be targetting using a class name within the header cell

This commit is contained in:
Mottie 2014-10-30 21:11:07 -05:00
parent 340b39a638
commit 5d53939cb0
3 changed files with 14 additions and 13 deletions

View File

@ -21,14 +21,16 @@
// BONUS TIP: disable a column using jQuery data directly
// but do it before the table initializes
// this code disables the sort on the "Date" column
$("table thead th:eq(5)").data("sorter", false);
$("table").tablesorter({
theme : 'blue',
headers: {
// disable sorting of the first column (we can use zero or the header class name)
'.first-name' : {
// disable sorting of the first & second column - before we would have to had made two entries
// note that "first-name" is a class on the span INSIDE the first column th cell
'.first-name, .last-name' : {
// disable it by setting the property sorter to false
sorter: false
}
@ -48,6 +50,7 @@
<p class="tip">
<em>NOTE!</em>
<ul>
<li>In tablesorter <span class="version">v2.18.1</span>, you can now target a column by the class name of an element inside of a header; note that the span has the targetted class name in the first name column.</li>
<li>In tablesorter v2.0.5 and older, only the metadata and headers options methods were available.</li>
<li>In versions 2.3+, columns can be disabled using any of the following methods (they all do the same thing), in order of priority:
<ul>
@ -64,8 +67,8 @@
<div id="demo"><table class="tablesorter">
<thead>
<tr>
<th class="first-name">First Name</th>
<th>Last Name</th>
<th><span class="first-name">First Name</span></th>
<th class="last-name">Last Name</th>
<th data-sorter="false">Age</th>
<th>Total</th>
<th class="sorter-false">Discount</th>

View File

@ -347,7 +347,7 @@
<li><a href="example-option-sortreset-sortrestart.html">Using sortReset &amp; sortRestart options</a> (<a href="#sortreset"><code>sortReset</code></a> &amp; <a href="#sortrestart"><code>sortRestart</code></a>)</li>
<li><a href="example-method-sortreset.html">Resetting the entire table sort</a> (<a href="#sortreset-method"><code>sortReset</code></a> method; v2.4.7)</li>
<li><a href="example-options-headers-locked.html">Lock sort order</a></li>
<li><a href="example-options-headers.html">Disable sort</a></li>
<li><a href="example-options-headers.html">Disable sort</a> (<span class="version updated">v2.18.1</span>)</li>
</ul>
</li>
<li>Modify a sort:
@ -369,7 +369,7 @@
<li><a href="example-multiple-tbodies.html">Sorting with Multiple Tbodies</a> (v2.2)</li>
<li><a href="example-header-column-span.html">Sorting Across Multiple Columns</a> (v2.3)</li>
<li><a href="example-option-show-processing.html">Show a processing icon during sorting/filtering</a> (v2.4)</li>
<li><a href="example-option-delay-init.html">Delay table initialization</a> (<a href="#delayinit"><code>delayinit</code></a>)</li>
<li><a href="example-option-delay-init.html">Delay table initialization</a> (<a href="#delayinit"><code>delayInit</code></a>)</li>
<li><a href="example-option-theme-metro-style.html">Set up a Metro style theme</a> (<span class="version">v2.16.4</span>)</li>
</ul>
</li>

View File

@ -1160,13 +1160,11 @@
}
for (k in obj) {
if (typeof k === 'string') {
if (getCell) {
// get header cell
$h = c.$headers.eq(indx).filter(k);
} else {
// get column indexed cell
$h = c.$headers.filter('[data-column="' + indx + '"]:last').filter(k);
}
$h = c.$headers.filter('[data-column="' + indx + '"]:last')
// header cell with class/id
.filter(k)
// find elements within the header cell with cell/id
.add( c.$headers.filter('[data-column="' + indx + '"]:last').find(k) );
if ($h.length) {
return obj[k];
}