datagrid加入键盘监听事件

(function ($) {
$.fn.ggrid = function (options) {
$(this).datagrid(options);

var grid = this;

//键盘监听
$(window).keydown(function (event) {
var currentRowIndex = $(grid).datagrid("getRowIndex", $(grid).datagrid("getSelected"));
switch (event.keyCode) {
case 38:
$(grid).datagrid("unselectAll");
var allLins = $(grid).datagrid("getRows").length;
currentRowIndex = currentRowIndex == 0 ? allLins : currentRowIndex-1;
$(grid).datagrid("selectRow", currentRowIndex );
break;
case 40:
$(grid).datagrid("unselectAll");
var allLins = $(grid).datagrid("getRows").length;
currentRowIndex = currentRowIndex == allLins ? 0 : currentRowIndex+1;
$(grid).datagrid("selectRow", currentRowIndex );
break;
}
});
return grid;
}
})(jQuery);

你可能感兴趣的:(datagrid加入键盘监听事件)