Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding a minimum character threshold #24

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ $('table').filterTable(); //if this code appears after your tables; otherwise, i
| `inputName` | string | filter-table | Name attribute of the filter input field |
| `inputType` | string | search | Tag name of the filter input itself |
| `label` | string | Filter: | Text to precede the filter input |
| `minChars` | integer | 1 | Filter is only applied to a table when at least this many characters are entered |
| `minRows` | integer | 8 | Only show the filter on tables with this number of rows or more |
| `placeholder` | string | search this table | HTML5 placeholder text for the filter input |
| `quickList` | array | [] | List of clickable phrases to quick fill the search |
Expand Down Expand Up @@ -83,6 +84,10 @@ Other than jQuery, the plugin will take advantage of Brian Grinstead's [bindWith

## Change Log

### 1.5.4

- Added a `minChars` option, thanks to [Darius Kazemi](https://github.com/dariusk), which specifies the minimum number of characters a user must enter into a filter before filtering occurs. Default is 1, meaning the moment the user begins to type, filtering will occur.

### 1.5.3

- **There is a potentially significant change in functionality in this version.** While the documentation offered the `inputSelector` option, within the code it was implemented as `filterSelector`. This has been corrected to match the documentation. Note that if you were previously using the `filterSelector` option to overcome this issue, you will need to change it to `inputSelector` to use the feature with this version.
Expand Down
5 changes: 3 additions & 2 deletions jquery.filtertable.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*
* Utilizes bindWithDelay() if available. https://github.com/bgrins/bindWithDelay
*
* @version v1.5.3
* @version v1.5.4
* @author Sunny Walker, [email protected]
*/
(function($) {
Expand Down Expand Up @@ -34,6 +34,7 @@
inputName: '', // name of filter input field
inputType: 'search', // tag name of the filter input tag
label: 'Filter:', // text to precede the filter input tag
minChars: 1, // don't start filtering until this many characters are entered
minRows: 8, // don't show the filter on tables with less than this number of rows
placeholder: 'search this table', // HTML5 placeholder text for the filter field
quickList: [], // list of phrases to quick fill the search
Expand All @@ -49,7 +50,7 @@

var doFiltering = function(table, q) { // handle the actual table filtering
var tbody=table.find('tbody'); // cache the tbody element
if (q==='') { // if the filtering query is blank
if (q==='' || q.length < settings.minChars) { // if the filtering query is blank or the number of chars entered is less than minChars
tbody.find('tr').show().addClass(settings.visibleClass); // show all rows
tbody.find('td').removeClass(settings.highlightClass); // remove the row highlight from all cells
if (settings.hideTFootOnFilter) { // show footer if the setting was specified
Expand Down
4 changes: 2 additions & 2 deletions jquery.filtertable.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.