jqGrid multiselect behavior when pressing special key

后端 未结 2 451
臣服心动
臣服心动 2020-12-03 16:17

What I was expecting from a multiselect behaviour is to behave just as normal as long as no special key is pressed. I mean, if you have a row selected and click on another

2条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-03 16:40

    I just came across the same question wanting to somehow mimic a behaviour like this: - Single-select on clicking a jqGrid's row - Multi-select when key-clicking a row (like CTRL + click)

    My solution uses jqGrid's "beforeSelectRow" event whoch passes the click event to it's handler. The handler differentiates between plain and "keyed" click. A keyed click is pass through, a plain click first eliminates a previous selection, than allows the event to bubble through.

    function(rowid,e) {
    
        if (e.ctrlKey==true) {
            return true;//CTRL clicked-->multi select
        } else {
            $('#CoolGrid').jqGrid('resetSelection');//Reset existing select
            return true;//Pass through new item selection
        }
    }
    

    Of course you may want to shorten this is a bit, but that way it seemed to be more clear, I think.

    You don't need neither multikey nor multiboxonly option for this. Multiselect option has to be set to true, of course.

提交回复
热议问题