jQuery Searchable Plugin
Latest version: v1.1.0 (View the changelog)
- Lightweight. This plugin is only ~1kB minified and gzipped!
- Fast. This plugin is optimized for fast, lagless searching even through large element sets.
- Multiple search types. This plugin provides three different search types out-of-the-box! Fuzzy matching, strict (case sensitive) matching and default (case insensitive) matching.
- Automatic row striping. When searching through a table, rows get hidden when they don't match. When using a CSS framework like Bootstrap this would mess up your table striping. This plugin makes allows you to define the CSS to be applied to odd and even rows, and updates them while searching.
- Custom show/hide. You can define custom functions for showing and hiding the elements while searching.
- Search anything. This plugin isn't restricted to use on tables, any set of elements that has 'rows' with 'columns' inside them can be used.
After downloading this plugin, include it in your HTML file after loading jQuery:
Note: If you want to support older browsers like <IE9, you can use the
jquery.searchable-ie.js instead of
jquery.searchable.js. This version includes a polyfill for the
Array.prototype.reduce function and is therefore slightly larger (a couple hundred bytes).
After that, you can simply initialize the plugin on the desired element. This example uses a table with an id of 'table'. By default, the plugin uses an input with an id of 'search' (read about how to change this in the Configuration section below):
This plugin provides the following configuration options:
||Defines the main selector within the element on which the plugin is initialized. This selects the 'rows' within the element.|
||Defines the child selector within the 'selector' defined above. This selects the 'columns' within the 'selector' element.|
||The input element that is used for the search input filter|
||Defines whether the element is striped and should be re-striped upon searching (either
||Defines the CSS object to apply to the odd rows (when
||Defines the CSS object to apply to the even rows (when
||Allows you to define a custom hiding function. This function accepts one parameter, which is the element (row) being hidden. By default it will use
||Allows you to define a custom show function. This function accepts one parameters, which is the element (row) being hidden. By default it will use
||Defines the matcher to be used when searching. Allowed values are
||Allows you to define a function to be called when the search is active. This function will be called whenever the user is typing into the search input and the search input is not empty. The searchable element and the search term will be passed to the function.|
||Allows you to define a function to be called when the search input is empty. This function will be called once when the search input is empty or cleared. The searchable element will be passed to the function.|
||Allows you to define a function to be called when the search input is focussed. The
||Allows you to define a function to be called when the search input is blurred. The
||Determines whether the search input should be cleared on page load (either
This example uses the configurations shown above to customize the plugin:
- Initial release.
- Added some events that allow you to call custom functions during the search lifecycle: onSearchActive, onSearchEmpty, onSearchFocus, onSearchBlur (view the configuration for more information).
- Added the
clearOnLoadsetting which allows you to clear the search input on page load / refresh.
Contributing & Issues
Please feel free to submit any issues or pull requests, they are more then welcome. When submitting an issue, please specify the version number and describe the issue in detail so that it can be solved as soon as possible!
Copyright (c) 2014 - Stidges - Licensed under the MIT license.