mirror of
https://github.com/Mottie/tablesorter.git
synced 2025-01-12 15:24:21 +00:00
Filter: add support for descending sort on selectSource values
This commit is contained in:
parent
1214f2bfdd
commit
0161acff0a
2
dist/js/widgets/widget-filter.min.js
vendored
2
dist/js/widgets/widget-filter.min.js
vendored
File diff suppressed because one or more lines are too long
@ -639,6 +639,7 @@ $(function(){
|
||||
<li><code>filter-false</code> - disable the filter for a specific header column.</li>
|
||||
<li><code>filter-select</code> - build a default select box for a column (shows unique column content). See the <a href="example-widget-filter-custom.html">custom filter widget</a> demo for an example.</li>
|
||||
<li><code>filter-select-nosort</code> - when a default select box is built, this option prevents the sorting of select options leaving them in their original table order (<span class="version">v2.16.3</span>).</li>
|
||||
<li><code>filter-select-sort-desc</code> - when a default select box is built, it is automatically set to an ascending sort. Adding this class name will perform a descending sort on the values (<span class="version">v2.27.7</span>).</li>
|
||||
<li><code>filter-match</code> - applies to "filter-select" columns and columns where the user can use the logical "or" search. Makes the filter/select match the column contents instead of exactly matching.</li>
|
||||
<li><code>filter-parsed</code> - set a column to filter through parsed data instead of the actual table cell content.</li>
|
||||
<li><code>filter-onlyAvail</code>
|
||||
|
@ -3314,8 +3314,12 @@ $('table').trigger('search', false);</pre></div>
|
||||
<li><span class="label warning">*NOTE*</span> because this example is providing a fixed select option source, it can not support "filter-onlyAvail" (only show available options after filtering).</li>
|
||||
</ul>
|
||||
|
||||
In <span class="version updated">v2.21.5</span>, this option will now override the <code>filter_function</code> options (<em>so you need to add them back!</em>), allowing the addition of custom select options and still maintain basic filtering action - see <a href="http://jsfiddle.net/Mottie/856bzzeL/117/">this demo</a> (<a class="external" href="http://stackoverflow.com/a/29506523/145346">ref</a>).<br>
|
||||
<br>
|
||||
<p>
|
||||
In <span class="version updated">v2.27.7</span>, an option to have a descending sort applied to this data can be done by adding a <code>"filter-select-sort-desc"</code> to the header cell. Adding a <code>"filter-select-nosort"</code> class name to a header to prevent sorting has been available since v2.16.3.
|
||||
</p>
|
||||
<p>
|
||||
In <span class="version updated">v2.21.5</span>, this option will now override the <code>filter_function</code> options (<em>so you need to add them back!</em>), allowing the addition of custom select options and still maintain basic filtering action - see <a href="http://jsfiddle.net/Mottie/856bzzeL/117/">this demo</a> (<a class="external" href="http://stackoverflow.com/a/29506523/145346">ref</a>).
|
||||
</p>
|
||||
In <span class="version updated">v2.17.0</span>, the <code>filter_selectSource</code> column can also be referenced by using a jQuery selector (e.g. class name or ID) that points to a table <em>header</em> cell.<br>
|
||||
<pre class="prettyprint lang-js">filter_selectSource : {
|
||||
".model-number" : [ "abc", "def", "ghi", "xyz" ]
|
||||
@ -7715,6 +7719,7 @@ $('select.external').html( opts );</pre>
|
||||
The <code>column</code> parameter is optional, but if included it is used:
|
||||
<ul>
|
||||
<li>To check the column header for a <code>filter-select-nosort</code> class name to prevent the sorting of options.</li>
|
||||
<li>To check the column header for a <code>filter-select-sort-desc</code> class name to preform a descending sort of options.</li>
|
||||
<li>To check tablesorter's <code>textSorter</code> option in case there are column specific sorting algorhithms set.</li>
|
||||
</ul>
|
||||
See the <a href="#function-getoptions"><code>getOptions</code></a> function description or the <a href="#widget-filter-selectsource"><code>filter_selectSource</code></a> option (under "An object containing column keys"; getJSON) for examples which use this function.
|
||||
|
@ -1548,6 +1548,7 @@
|
||||
var cts, txt, indx, len, parsedTxt, str,
|
||||
c = table.config,
|
||||
validColumn = typeof column !== 'undefined' && column !== null && column >= 0 && column < c.columns,
|
||||
direction = validColumn ? c.$headerIndexed[ column ].hasClass( 'filter-select-sort-desc' ) : false,
|
||||
parsed = [];
|
||||
// get unique elements and sort the list
|
||||
// if $.tablesorter.sortText exists ( not in the original tablesorter ),
|
||||
@ -1588,8 +1589,8 @@
|
||||
// sort parsed select options
|
||||
cts = c.textSorter || '';
|
||||
parsed.sort( function( a, b ) {
|
||||
var x = a.parsed,
|
||||
y = b.parsed;
|
||||
var x = direction ? b.parsed : a.parsed,
|
||||
y = direction ? a.parsed : b.parsed;
|
||||
if ( validColumn && typeof cts === 'function' ) {
|
||||
// custom OVERALL text sorter
|
||||
return cts( x, y, true, column, table );
|
||||
|
Loading…
Reference in New Issue
Block a user