码迷,mamicode.com
首页 > 其他好文 > 详细

easyui datagrid shift 多选

时间:2015-09-23 16:21:21      阅读:317      评论:0      收藏:0      [点我收藏+]

标签:

<!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")[0].onkeydown = keyPress;
        $("body")[0].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 = 0;
            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: 16, CTRL: 17, ALT: 18, DOWN: 40, RIGHT: 39, UP: 38, LEFT: 37 };
    var selectIndexs = { firstSelectRowIndex: 0, lastSelectRowIndex: 0 };
    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 = 0;
                $(#datagrid).datagrid(options).singleSelect = true;
                break;
            case KEY.CTRL:
                inputFlags.isCtrlDown = false;
                selectIndexs.firstSelectRowIndex = 0;
                $(#datagrid).datagrid(options).singleSelect = true;
                break;
            default:
        }
    }
</script>

</body>
</html>

 

easyui datagrid shift 多选

标签:

原文地址:http://www.cnblogs.com/bingguang/p/4832270.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!