easyui datagrid shift 多选

时间:2022-09-22 14:58:00
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width" />
<title>IndexV6</title> <link href="/Plugs/jquery-easyui-1.4.3/themes/default/easyui.css" rel="stylesheet" />
<link href="/Plugs/jquery-easyui-1.4.3/themes/icon.css" rel="stylesheet" />
<script src="/Plugs/jquery-easyui-1.4.3/jquery.min-1.11.3.js"></script> <script src="/Plugs/jquery-easyui-1.4.3/jquery.easyui.min-1.4.3.js"></script> <script src="/Plugs/jquery-easyui-1.4.3/locale/easyui-lang-zh_CN-1.0.js"></script>
<script src="/Plugs/jquery-easyui-1.4.3/pengbg/pengbgEasyuiControl.js"></script>
</head>
<body> <h2>IndexV6</h2>
<table class="easyui-datagrid" title="" style="width: 408px"
data-options="url:'/Test/Data',onClickRow:fun,
singleSelect: true,
" id="datagrid">
<thead>
<tr>
<th data-options="field:'ck',checkbox: 'true'"></th>
<th data-options="field:'UpdateUser'"></th>
</tr>
</thead>
</table> <script>
$(document).ready(function () {
$("body")[].onkeydown = keyPress;
$("body")[].onkeyup = keyRelease;
});
function fun(index, row) {
if (index != selectIndexs.firstSelectRowIndex && !inputFlags.isShiftDown) {
selectIndexs.firstSelectRowIndex = index; //alert('firstSelectRowIndex, sfhit = ' + index);
}
if (inputFlags.isShiftDown) {
$('#datagrid').datagrid('clearSelections');
selectIndexs.lastSelectRowIndex = index;
var tempIndex = ;
if (selectIndexs.firstSelectRowIndex > selectIndexs.lastSelectRowIndex) {
tempIndex = selectIndexs.firstSelectRowIndex;
selectIndexs.firstSelectRowIndex = selectIndexs.lastSelectRowIndex;
selectIndexs.lastSelectRowIndex = tempIndex;
}
for (var i = selectIndexs.firstSelectRowIndex ; i <= selectIndexs.lastSelectRowIndex ; i++) {
$('#datagrid').datagrid('selectRow', i);
}
}
}
var KEY = { SHIFT: , CTRL: , ALT: , DOWN: , RIGHT: , UP: , LEFT: };
var selectIndexs = { firstSelectRowIndex: , lastSelectRowIndex: };
var inputFlags = { isShiftDown: false, isCtrlDown: false, isAltDown: false }; function keyPress(event) {//响应键盘按下事件
var e = event || window.event;
var code = e.keyCode | e.which | e.charCode;
switch (code) {
case KEY.SHIFT:
inputFlags.isShiftDown = true;
$('#datagrid').datagrid('options').singleSelect = false;
break;
case KEY.CTRL:
inputFlags.isCtrlDown = true;
$('#datagrid').datagrid('options').singleSelect = false;
break;
default:
}
} function keyRelease(event) { //响应键盘按键放开的事件
var e = event || window.event;
var code = e.keyCode | e.which | e.charCode;
switch (code) {
case KEY.SHIFT:
inputFlags.isShiftDown = false;
selectIndexs.firstSelectRowIndex = ;
$('#datagrid').datagrid('options').singleSelect = true;
break;
case KEY.CTRL:
inputFlags.isCtrlDown = false;
selectIndexs.firstSelectRowIndex = ;
$('#datagrid').datagrid('options').singleSelect = true;
break;
default:
}
}
</script> </body>
</html>