diff --git a/docs/example-widget-filter-custom.html b/docs/example-widget-filter-custom.html index 61e0b64b..cc7055d3 100644 --- a/docs/example-widget-filter-custom.html +++ b/docs/example-widget-filter-custom.html @@ -158,6 +158,12 @@

Notes

diff --git a/docs/example-widget-filter.html b/docs/example-widget-filter.html index c3cbc7c2..af8bec81 100644 --- a/docs/example-widget-filter.html +++ b/docs/example-widget-filter.html @@ -18,6 +18,14 @@ /* override the vertical-align top in the blue theme */ .notes.tablesorter-blue tbody td { vertical-align: middle; } + @@ -189,11 +197,20 @@ $(function(){


-
+

Notes

    +
  • In v2.16+, +
      +
    • When a default filter select is added to a column, it is now sorted using the textSorter setting, and falls back to an alphanumeric sort (v2.16.3).
    • +
    • Adding a class of "filter-select-nosort" will now leave the select options unsorted (v2.16.3).
    • +
    • Added filter_placeholder option (v2.16.0).
    • +
    • Added filter_selectSource option (v2.16.3).
    • +
    • updated filter_reset option (v2.16.3).
    • +
    +
  • In v2.15,
    • The filter_anyMatch widget option was completely removed. Sorry for not deprecating this option, but the filter any match code was completely rewritten.
    • @@ -231,29 +248,194 @@ $(function(){

      Options

      -

      Filter widget defaults (added inside of tablesorter widgetOptions)

      -
        -
      • filter_anyMatch : null - jQuery selector string (or jQuery object) of external anyMatch filter (removed in v2.15; please see the demo for more details).
      • -
      • filter_childRows : false - if true, filter includes child row content in the search.
      • -
      • filter_columnFilters : true - if true, a filter will be added to the top of each table column.
      • -
      • filter_cssFilter : '' - extra css class name(s) applied to the table row containing the filters & the inputs within that row. This option can either be a string (class applied to all filters) or an array (class applied to indexed filter).
      • -
      • filter_defaultAttrib : 'data-value' - this option contains the name of the data-attribute which contains the default (starting) filter value.
      • -
      • filter_external : '' - jQuery selector (or object) pointing to an input to be used to match the contents of any column; please refer to the updated filter-any-match demo for limitations (v2.15).
      • -
      • filter_filteredRow : 'filtered' - css class name added to filtered rows (rows that are not showing); needed by pager plugin.
      • -
      • filter_formatter : null - add custom filter elements to the filter row.
      • -
      • filter_functions : null - add custom filter functions using this option.
      • -
      • filter_hideFilters : false - if true, filters are hidden initially, but can be revealed by clicking on the filter icon *.
      • -
      • filter_ignoreCase : true - if true, make all searches case-insensitive.
      • -
      • filter_liveSearch : true - if true, search column content while the user types (with a delay). If false, the user must press enter to start the search. If set to a number, when the length of the input text reaches this minimum length, a search will initiate.
      • -
      • filter_onlyAvail : 'filter-onlyAvail' - a header with a select dropdown & this class name will only show available (visible) options within that drop down.
      • -
      • filter_reset : null - jQuery selector string of an element used to reset the filters.
      • -
      • filter_saveFilters : false - Uses the $.tablesorter.storage utility to save the most recent filters.
      • -
      • filter_searchDelay : 300 - typing delay in milliseconds before starting a search.
      • -
      • filter_serversideFiltering : false - if true, filter will be done server-side. The client-side filtering will be disabled, but the ui and events will still be used.
      • -
      • filter_startsWith : false - if true, filter start from the beginning of the cell contents.
      • -
      • filter_useParsedData : false - filter all data using parsed content.
      • -
      - +

      Filter widget defaults (added inside of tablesorter widgetOptions)

      +
      + TIP! Click on the link in the function column to reveal full details (or toggle|show|hide all) or double click to update the browser location. +
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      OptionDefaultDescription
      filter_childRowsfalseif true, filter includes child row content in the search.
      filter_columnFilterstrueif true, a filter will be added to the top of each table column.
      '' + Extra css class name(s) applied to the table row containing the filters & the inputs within that row (v2.15). +
      +
      + This option can either be a string (class applied to all filters) or an array (class applied to indexed filter). +
      +
      filter_defaultAttrib'data-value'this option contains the name of the data-attribute which contains the default (starting) filter value.
      filter_external'' + Set to a jQuery selector (or object) pointing to an input to be used to match the contents of any column (v2.15). +
      +
      + Please refer to the updated filter-any-match demo for the limitations of this setting. +
      +
      filter_filteredRow'filtered'Css class name added to filtered rows (rows that are not showing); needed by pager plugin.
      null + Add custom filter element(s) to the filter row +
      +
      + Custom filter elements include: + +
      +
      null + Add custom filter functions using this option. +
      +
      + See the custom filter widget functions demo for more details and numerous examples. +
      +
      filter_hideEmptytrueHide filter row when the table is empty (v2.15).
      filter_hideFiltersfalseIf true, filters are hidden initially, but can be revealed by hovering over the filter row, or giving a filter input focus (tabbing down the page).
      filter_ignoreCasetrueIf true, all searches are case-insensitive.
      filter_onlyAvail'filter-onlyAvail'A header with a select dropdown & this class name set, will only show available (visible) options within that drop down.
      filter_placeholder{ search : '', select : '' }Default placeholder text (overridden by any header "data-placeholder" setting; v2.16).
      filter_resetnulljQuery selector string of an element used to reset the filters (v2.4; v2.16.0).
      filter_saveFiltersfalseUses the $.tablesorter.storage utility to save the most recent filters.
      filter_searchDelay300Typing delay in milliseconds before starting a search.
      filter_selectSourcenullInclude a function to return an array of values to be added to the column filter select (v2.16.0).
      filter_serversideFilteringfalseIf true, filter will be done server-side. The client-side filtering will be disabled, but the ui and events will still be used.
      filter_startsWithfalseIf true, filter start from the beginning of the cell contents.
      filter_useParsedDatafalseFilter all data using parsed content.
      Removed options
      filter_anyMatchnulljQuery selector string (or jQuery object) of external anyMatch filter (removed in v2.15; please see the demo for more details)

      Classes

      @@ -262,9 +444,16 @@ $(function(){
      • filter-false - disable the filter for a specific header column.
      • filter-select - build a default select box for a column (shows unique column content). See the custom filter widget demo for an example.
      • +
      • filter-select-nosort - when a default select box is built, this option prevents the sorting of select options leaving them in their original table order (v2.16.3).
      • filter-match - 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.
      • filter-parsed - set a column to filter through parsed data instead of the actual table cell content.
      • -
      • filter-onlyAvail - show only available (visible) options within a default select box. See the custom filter widget demo "Discount" column for an example.
      • +
      • filter-onlyAvail +
          +
        • Show only available (visible) options within a default select box.
        • +
        • This class name is set by the filter_onlyAvail option.
        • +
        • See the custom filter widget demo "Discount" column for an example.
        • +
        +
diff --git a/js/jquery.tablesorter.widgets.js b/js/jquery.tablesorter.widgets.js index 3353330d..9cd1fcaf 100644 --- a/js/jquery.tablesorter.widgets.js +++ b/js/jquery.tablesorter.widgets.js @@ -1041,7 +1041,8 @@ ts.filter = { }, 0); }, getOptionSource: function(table, column, onlyAvail) { - var c = table.config, + var cts, + c = table.config, wo = c.widgetOptions, arry = false, source = wo.filter_selectSource; @@ -1065,7 +1066,25 @@ ts.filter = { arry = $.grep(arry, function(value, indx) { return $.inArray(value, arry) === indx; }); - return (ts.sortNatural) ? arry.sort(function(a, b) { return ts.sortNatural(a, b); }) : arry.sort(true); + if (c.$headers.filter('[data-column="' + column + '"]:last').hasClass('filter-select-nosort')) { + return arry; + } else { + cts = c.textSorter || ''; + return arry.sort(function(a, b){ + if ($.isFunction(cts)) { + // custom OVERALL text sorter + return cts(a, b, 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); + } else if (ts.sortNatural) { + // fall back to natural sort + return ts.sortNatural(a, b); + } + // using an older version! do a basic sort + return true; + }); + } }, getOptions: function(table, column, onlyAvail) { var rowIndex, tbodyIndex, len, row, cache, cell,