Hi,
I have specific requirements for keyboard navigation within a grid. I have implemented custom navigation in the grid that works very well for text box inputs. However, it does not work well when I navigate across cells containing dropdownlists, as the arrow keys change the values in the list as the user navigates away from these cells.
I use the following function to capture keydown events within the grid:
// Key-down event handler to provide custom navigation within the grid.
$("#auto_gen_conn_mngr_grid table").on("keydown", "td", function (e) {
switch (e.keyCode ? e.keyCode : e.which) {
case kendo.keys.UP:
e.preventDefault();
e.stopPropagation();
NavigateVertically(this, navDirection.UP);
break;
case kendo.keys.ENTER:
case kendo.keys.DOWN:
e.preventDefault();
e.stopPropagation();
NavigateVertically(this, navDirection.DOWN);
break;
case kendo.keys.LEFT:
e.preventDefault();
e.stopPropagation();
NavigateHorizontally(this, navDirection.LEFT);
break;
case kendo.keys.TAB:
e.preventDefault(); // Keep Tab from navigating to elements outside of the grid.
e.stopPropagation();
case kendo.keys.RIGHT:
e.preventDefault();
e.stopPropagation();
NavigateHorizontally(this, navDirection.RIGHT);
break;
}
});
The problem is, that before this function executes, the dropdown list has already received the 'select' event and modified it's selected item. I can add an event handler to my list's editor template, which uses preventDefault() to cancel the selection. But I can't tell how to differentiate between events that should vs. should not modify the selection.
I would like the selection to be modified only when the user uses holds the 'ctrl' key while pressing the navigational key (i.e. arrows, tab, or enter) or uses a mouse click to click the new selection.
I can do this in one of two ways, but I am stuck on both:
method 1: intercept the keydown event before it is handled at the dropdownlist.
problem 1: the event has already gone to the dropdownlist before I capture it, using the code above.
method 2: add a handler in the list's editor template for the 'select' event, then use e.preventDefault() when the user is pressing a navigational key without holding down the 'ctrl' key.
problem 2: I don't know if it is possible to get the keystroke information from the context of the list editor's onSelect handler.
And finally, if there is no way to accomplish either of the above, disabling keyboard navigation within the dropdown list would be an acceptable compromise. This is not the preferred approach, but if it is possible to configure the dropdownlist to only accept mouse clicks in order to change the selection, that would enable the users to navigate the grid with the keyboard without modifying the selections in the dropdown lists.
Thanks,
Ryan