Skip to content

Commit

Permalink
Merge pull request #12 from penguinpowernz/autofocus
Browse files Browse the repository at this point in the history
Optional autofocus the filter table textbox through an option
  • Loading branch information
sunnywalker committed Mar 19, 2014
2 parents 28eb410 + 0dce623 commit 2503e6b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
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

0 comments on commit 2503e6b

Please sign in to comment.