KeyTable is a Javascript library which provides keyboard navigation and event binding for any HTML table. With KeyTable Excel style table navigation can be employed to provide features such as editing of a table without requiring a mouse. As a further bonus, KeyTable integrates seamlessly with DataTables.
Let’s jump straight into an example: the table below is editable through keyboard navigation. Simply navigate to the cell you wish to edit and hit return. This initialises the excellent jEditable plug-in for jQuery – make your edit and then hit return again to save.
Usage
Using KeyTable on a plain HTML is as simple as creating a new object:
var keys = new KeyTable();
By default, KeyTable will attach itself to the first table it finds in the DOM with the class ‘KeyTable’ and apply basic navigation controls. There are a number of initialisation parameters that you can pass into the constructor to provide a bit more control over the default behaviour:
Once KeyTable has been initialised you will most likely wish to add event listeners to the cell in the table. This is done thought the methods presented by the ‘event’ object of KeyTable. The following events are supported:
Each of these events is applied by calling event.{event_name}() (where event_name is of course one of the events from above). This function accepts either two or three inputs:
# /* Example event listener */
# keys.event.focus( 1, 3, function() {
# /* processing on cell 1,3 ... */
# } );
#
# /* this is exactly the same as */
# keys.event.focus( $('#example tbody tr:eq(3) td:eq(1)')[0], function() {
# /* processing on cell 1,3 ... */
# } );
Events listeners can be removed through the ‘event.remove.{event_name}’ object. This function call expects the same inputs as the methods to add events, but in this case the event listener function is optional. If it is left off then all events of that type are removed from that cell.
Requirements and support:
KeyTable has been tested and works great on:
* IE6+
* Firefox 3+
* Safari 3+ (Safari 4 is required for correct tabbing with a “form” table)
* Opera 9.6 (Opera 10a has a rendering bug – bug filed)
I expect that plenty of other browser will work just fine as well. There is one little hiccup in the key event handling. It would appear that there is very little consistency between browsers on however to handle repeat events on ’special’ keys such as arrow keys. However, KeyTable does detection to overcome this issue.
KeyTable expects the target table to be well defined and to have a tbody tag. It will not work with out this! It also utilises jQuery’s selector and event methods in order to provide easy cross platform implementation. However, since my usage of jQuery is limited to just these two components it would be relatively trivial to port KeyTable to any other library you like.
Demo: http://www.sprymedia.co.uk/article/KeyTable
Download: http://www.sprymedia.co.uk/software/KeyTable/KeyTable.zip
Source: http://www.sprymedia.co.uk/article/KeyTable

Related Listings:
RSS feed for comments on this post. TrackBack URL
October 4th, 2009 at 6:51 am
[...] This post was mentioned on Twitter by Open4G Media and Web Development News. Web Development News said: KeyTable – jQuery Table Plugin: KeyTable is a Javascript library which provides keyboard navigation and e.. http://bit.ly/4fgShD [...]
October 7th, 2009 at 5:40 am
[...] KeyTable – jQuery Table Plugin [...]