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 ... */ } );
As noted in the above arguments list, when passing in coordinates to attach an event listener to a cell, you can pass null for either (or both) the x and y coordinates. This generalises the event target to occur on the given x or y coordinate, regardless of the other point. For example this allows you to target whole rows or columns, rather than just individual cells.
/* Event listener for a row */ keys.event.focus( null, 0, function() { /* handler for focus events in first row ... */ } ); /* Event listener for a column */ keys.event.focus( 3, null, function() { /* handler for focus events in forth column ... */ } ); /* Event listener for all cells */ keys.event.focus( null, null, function() { /* handler for focus events on all cells ... */ } );
There are three parameters which are passed into the event handler, which can then be used by your handler function to perform whatever actions are necessary:
There is no return parameter expected from the event handler.
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.