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

Optional autofocus the filter table textbox through an option #12

Merged
merged 2 commits into from Mar 19, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -48,6 +48,7 @@ $('table').filterTable(); //if this code appears after your tables; otherwise, i
| `quickListGroupTag` | string | '' | Tag name surrounding quick list items (e.g., `ul`) |
| `quickListTag` | string | a | Tag name of each quick list item (e.g., `a` or `li`) |
| `visibleClass` | string | visible | Class applied to visible rows |
| `autofocus` | boolean | true | Makes the filter input field autofocused |

## Styling

Expand Down
8 changes: 7 additions & 1 deletion jquery.filtertable.js
Expand Up @@ -38,7 +38,8 @@
quickListClass: 'quick', // class of each quick list item
quickListGroupTag: '', // tag surrounding quick list items (e.g., ul)
quickListTag: 'a', // tag type of each quick list item (e.g., a or li)
visibleClass: 'visible' // class applied to visible rows
visibleClass: 'visible', // class applied to visible rows
autofocus: true // make the filter input field autofocused
},
hsc = function(text) { // mimic PHP's htmlspecialchars() function
return text.replace(/&/g, '&amp;').replace(/"/g, '&quot;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
Expand Down Expand Up @@ -78,6 +79,11 @@
}
container.prepend(settings.label+' '); // add the label for the filter field
filter = $('<input type="'+settings.inputType+'" placeholder="'+settings.placeholder+'" name="'+settings.inputName+'" />'); // build the filter field

if ( settings.autofocus ) {
filter.attr("autofocus", "autofocus");
}

if ($.fn.bindWithDelay) { // does bindWithDelay() exist?
filter.bindWithDelay('keyup', function() { // bind doFiltering() to keyup (delayed)
doFiltering(t, $(this).val());
Expand Down