美文网首页
easyui使用shift或ctrl多选

easyui使用shift或ctrl多选

作者: 灬冷枫 | 来源:发表于2018-11-29 00:11 被阅读0次

    今天在网上找的demo,使用后一直报错,以下为自己修改后的版本。


    <body class="easyui-layout" data-options="fit:true,border:true" onkeydown="javascript:keyDown(event);">

    <script type="text/javascript">

    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 MultiSelect(index, row) {

    if (index !=selectIndexs.firstSelectRowIndex && !inputFlags.isShiftDown) {

    selectIndexs.firstSelectRowIndex = index;

    }

    if (inputFlags.isShiftDown) {

    inputFlags.isShiftDown =false;

    $('#orderDataGrid').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++){

    $('#orderDataGrid').datagrid('checkRow',i);

    }

    selectIndexs.firstSelectRowIndex =0;

    selectIndexs.lastSelectRowIndex =0;

    }

    }

    function keyDown(event) {//响应键盘按下事件

        var e = event ||window.event;

    var code =e.keyCode |e.which |e.charCode;

    switch (code) {

    case KEY.SHIFT:

    inputFlags.isShiftDown =true;

    break;

    case KEY.CTRL:

    inputFlags.isShiftDown =true;

    break;

    default:

    }

    }

    orderDataGrid =$('#orderDataGrid').datagrid({

    onLoadSuccess:myfilter,

    url:'',

    striped :true,

    rownumbers :true,

    pagination :true,

    singleSelect:false,

    checkOnSelect:true,

    selectOnCheck:true,

    idField :'id',

    sortName :'PayTime',

    sortOrder :'desc',

    pageSize :100,

    onClickRow:function (index, row)

    {

    MultiSelect(index,row);

    },

    onCheck:function(index,row){

    MultiSelect(index,row);

    },

    frozenColumns: [[

    {field:'id',title:'id',width:'60',checkbox:true },

    {field:'tidstr',title:'订单号',width:'150',

    sortable :true,

    formatter :function(value, row, index) {

    return row['id'];

    }},]]}

    </script>

    相关文章

      网友评论

          本文标题:easyui使用shift或ctrl多选

          本文链接:https://www.haomeiwen.com/subject/migtcqtx.html