mirror of
https://github.com/Mottie/tablesorter.git
synced 2025-01-12 15:24:21 +00:00
Filter: select options are now parsed before being sorted
This commit is contained in:
parent
f1f830b2bb
commit
9a4acdf6e8
@ -160,7 +160,7 @@
|
||||
<ul>
|
||||
<li>In <span class="version">v2.16.3</span>,
|
||||
<ul>
|
||||
<li>When a default filter select is added to a column, it is now sorted using the <code>textSorter</code> setting, and falls back to an alphanumeric sort.</li>
|
||||
<li>When a default filter select is added to a column, it is now parsed from the assigned parser, then sorted using the <code>textSorter</code> setting, and falls back to an alphanumeric sort.</li>
|
||||
<li>Adding a class of <code>"filter-select-nosort"</code> will now leave the select options unsorted.</li>
|
||||
</ul>
|
||||
</li>
|
||||
@ -188,7 +188,7 @@
|
||||
<li>The select is populated by the column text contents with repeated content combined (i.e. There are three "Aaron"'s in the first column, but only one in the dropdown.</li>
|
||||
<li>Select options are automatically <del>alphanumerically</del> (new in v2.4) sorted. Changed in <span class="version updated">v2.16.3</span>:
|
||||
<ul>
|
||||
<li>The select contents are now sorted using the <a href="index.html#textsorter"><code>textSorter</code></a> option</li>
|
||||
<li>The select contents are now parsed from the assigned parser, then sorted using the <a href="index.html#textsorter"><code>textSorter</code></a> option</li>
|
||||
<li>Add a class name of <code>"filter-select-nosort"</code> to prevent sorting the select options (<span class="version">v2.16.3</span>).</li>
|
||||
</ul>
|
||||
</li>
|
||||
|
@ -204,7 +204,7 @@ $(function(){
|
||||
<ul>
|
||||
<li>In <span class="version updated">v2.16+</span>,
|
||||
<ul>
|
||||
<li>When a default filter select is added to a column, it is now sorted using the <code>textSorter</code> setting, and falls back to an alphanumeric sort (<span class="version updated">v2.16.3</span>).</li>
|
||||
<li>When a default filter select is added to a column, it is now parsed from the assigned parser, then sorted using the <code>textSorter</code> setting, and falls back to an alphanumeric sort (<span class="version updated">v2.16.3</span>).</li>
|
||||
<li>Adding a class of <code>"filter-select-nosort"</code> will now leave the select options unsorted (<span class="version">v2.16.3</span>).</li>
|
||||
<li>Added <code>filter_placeholder</code> option (<span class="version">v2.16.0</span>).</li>
|
||||
<li>Added <code>filter_selectSource</code> option (<span class="version">v2.16.3</span>).</li>
|
||||
|
@ -1044,6 +1044,7 @@ ts.filter = {
|
||||
var cts,
|
||||
c = table.config,
|
||||
wo = c.widgetOptions,
|
||||
parsed = [],
|
||||
arry = false,
|
||||
source = wo.filter_selectSource;
|
||||
|
||||
@ -1066,24 +1067,41 @@ ts.filter = {
|
||||
arry = $.grep(arry, function(value, indx) {
|
||||
return $.inArray(value, arry) === indx;
|
||||
});
|
||||
|
||||
if (c.$headers.filter('[data-column="' + column + '"]:last').hasClass('filter-select-nosort')) {
|
||||
// unsorted select options
|
||||
return arry;
|
||||
} else {
|
||||
// parse select option values
|
||||
$.each(arry, function(i, v){
|
||||
// parse array data using set column parser; this DOES NOT pass the original
|
||||
// table cell to the parser format function
|
||||
parsed.push({ t : v, p : c.parsers && c.parsers[column].format( v, table, [], column ) || v });
|
||||
});
|
||||
|
||||
// sort parsed select options
|
||||
cts = c.textSorter || '';
|
||||
return arry.sort(function(a, b){
|
||||
parsed.sort(function(a, b){
|
||||
var x = a.p, y = b.p;
|
||||
if ($.isFunction(cts)) {
|
||||
// custom OVERALL text sorter
|
||||
return cts(a, b, true, column, table);
|
||||
return cts(x, y, true, column, table);
|
||||
} else if (typeof(cts) === 'object' && cts.hasOwnProperty(column)) {
|
||||
// custom text sorter for a SPECIFIC COLUMN
|
||||
return cts[column](a, b, true, column, table);
|
||||
return cts[column](x, y, true, column, table);
|
||||
} else if (ts.sortNatural) {
|
||||
// fall back to natural sort
|
||||
return ts.sortNatural(a, b);
|
||||
return ts.sortNatural(x, y);
|
||||
}
|
||||
// using an older version! do a basic sort
|
||||
return true;
|
||||
});
|
||||
// rebuild arry from sorted parsed data
|
||||
arry = [];
|
||||
$.each(parsed, function(i, v){
|
||||
arry.push(v.t);
|
||||
});
|
||||
return arry;
|
||||
}
|
||||
},
|
||||
getOptions: function(table, column, onlyAvail) {
|
||||
|
Loading…
Reference in New Issue
Block a user