# tablesorter

## Filter Widget External Search

### Flexible client-side table sorting

Back to documentation

### Notes

- In v2.26.2, The not match (`!`) limitation is no longer in place. Try searching in the "Match any column" for
  .
- In v2.22.0, AnyMatch searches for specific columns will no longer save filter data to each targeted column. See the "AnyMatch Searches" section below.
- In v2.20.0, @MasksimProgr added a method to allow targeting a specific column using the anyMatch filter. Find more details in the AnyMatch section below.
- In v2.18.0, the external search data column can be set to multiple columns (`data-column="0-2,4,6-7"`). Please see the Filter Widget External Inputs demo for more details.
- In v2.17.8, added a default fuzzy search to the "First Name" column.
- This is a demo of the `filter_external` option (added v2.15).
- In v2.15
  - The `filter_anyMatch` option has been removed (added v2.13.3; removed in v2.15)
  - A new option `filter_external` has been added. It is set to a jQuery selector string (`'.search'`) or jQuery object (`$('.search')`) targeting an external input.
  - So now a table can include both a filter row (`filter_columnFilters` is `true`, i.e. the internal table filters) and any number of external search inputs (as set by the `filter_external` option).
  - The external search results must have a `data-column="#"` attribute set, where `#` is the index of the column (zero-based) that the input targets, to have an input search all table content, set the data column attribute to `"all"` to match any column.
  - The `$.tablesorter.bindSearch` function (see demo) does exactly the same thing as the `filter_external` option. The major difference is seen when using ajax to populate the table, the initial filter values can be set before tablesorter initialization when using the `filter_external` option; whereas, the bind search function can not set initial filter values and is usually executed after tablesorter initialization.

### AnyMatch Searches

- In v2.27.5, you can target specific columns using a partial match of the header text. Updated below.
- In v2.20.0, the anyMatch filter can target specific columns using the following format:

      {column}:{query}

  - where `{column}` is the column one-based index (non-developers count from one) or a partial match of the case-insensitive column text.
  - and `{query}` is the specific column query.
  You can disable this type of search by setting the new `filter_columnAnyMatch` option to `false`.

  #### Examples

  - or
    Find values > 30 in the age column
  - or
    Include a fuzzy search (see `filter_defaultFilter` setting) and look for "aa" in the first name column (four results should show).
  - or
    Find ranks with a "5" in them and find dates with a "12"
  - This column specific anyMatch does not support using an OR column search like `1:5|7:12`.
  - Find names (First AND Last) that contain an "e". This searches both name columns, so it is essentially the same as using
    . Remember this method does not provide an "OR" type search.

  * NOTE * Fixed in v2.22.0. When a AnyMatch search of this type is active, it adds filter queries to specific columns, so if the filters are saved and you reload the page, the specified column filters will become populated along with the AnyMatch search.

### Limitations

- The any-match search method has limitations applied. It does not support all of the per column search features! So, at this time, the following types of queries are not allowed as the results will cause confusion:
  - Search operators - A search for values equal, greater or less than values (`> >= <= <`) is not allowed because tables that contain both numbers and text (in separate columns). For example:

        "Fred" > "1"  // true*
        "Fred" < "10" // false
        "Fred" > 1    // false (numeric comparisons occur with parsed table data)
        "Fred" > 1    // false
        "Fred" < 10   // false

    * For comparisons, letters have a greater ASCII value than numbers.
  - Range query - A search for any number range (`1 - 10`) is not allowed because, if any columns contain text, then no rows will result. The examples are the same as the search operators examples above.
  - Allowed filters include plain text matching, fuzzy search (`~`), exact match (`"`), wild card matches( `?` or `*`), regex (`/\d/g`), and logical and (`a && b`)/or (`a|b`) matches.
  - Not Match query - No longer a limitation! (v2.26.2)

    Try searching for

    A search for not matches (`!a`) is not allowed because tables that contain both numbers and text (in separate columns) will always show all rows. For example:

        "Frank".search("a")    //  2 (a match, so this row "may" be hidden)
        "Fred".search("a")      // -1 (a not match! so this row will always show)
        "25".search("a")        // -1 (a not match! so this row will always show)
        "1/1/2014".search("a")  // -1 (a not match! so this row will always show)

- Setting this option should work properly with or without the column filters. The only issue you would have is if you triggered a search on the table using an array with undefined or null array values, like this:

      // apply "2?%" filter to the fifth column (zero-based index)
      var columns = [];
      columns[5] = '2?%';
      // anyMatch will kick in on undefined column filters,
      // unless the array looks like this: columns = [ '', '', '', '', '', '2?%' ]
      $('table').trigger('search', [ columns ]);

# Demo

(Match any column)
(First Name; fuzzy search... try "be")

Rank | First Name | Last Name | Age | Total | Discount | Date
--- | --- | --- | --- | --- | --- | ---
1 | Philip Aaron | Johnson Sr Esq | 25 | $5.95 | 22% | Jun 26, 2004 7:22 AM
11 | Aaron | Hibert | 12 | $2.99 | 5% | Aug 21, 2009 12:21 PM
12 | Brandon Clark | Henry Jr | 51 | $42.29 | 18% | Oct 13, 2000 1:15 PM
111 | Peter | Parker | 28 | $9.99 | 20% | Jul 6, 2006 8:14 AM
21 | John | Hood | 33 | $19.99 | 25% | Dec 10, 2002 5:14 AM
013 | Clark | Kent Sr. | 18 | $15.89 | 44% | Jan 12, 2003 11:14 AM
005 | Bruce | Almighty Esq | 45 | $153.19 | 44% | Jan 18, 2021 9:12 AM
10 | Alex | Dumass | 13 | $5.29 | 4% | Jan 8, 2012 5:11 PM
16 | Jim | Franco | 24 | $14.19 | 14% | Jan 14, 2004 11:23 AM
166 | Bruce Lee | Evans | 22 | $13.19 | 11% | Jan 18, 2007 9:12 AM
100 | Brenda Lee | McMasters | 18 | $55.20 | 15% | Feb 12, 2010 7:23 PM
55 | Dennis | Bronson | 65 | $123.00 | 32% | Jan 20, 2001 1:12 PM
9 | Martha | delFuego | 25 | $22.09 | 17% | Jun 11, 2011 10:55 AM

# Javascript

# HTML

Next up: jQuery custom filter widget external inputs ››