easyui datagrid shift 다중 선택

7229 단어
<!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>

좋은 웹페이지 즐겨찾기