jqGrid multiselect behavior when pressing special key
Asked Answered
M

2

5

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 with no other key pressed, then it should select the new one and deselect the old row. Well, jqGrid’s standard options lets you choose between always regular behaviour, or always multiselect. You can’t have multiselect only when a special key is pressed.

Is there a way I can achieve this?

Mumbletypeg answered 15/9, 2010 at 13:20 Comment(0)
S
5

jqGrid has several selection strategy, all using multiselect:true. To demonstrate there I created three example:

  1. If you define only multiselect:true: http://www.ok-soft-gmbh.com/jqGrid/DataToMultiSelect2.htm. This is standard behavior which you not like.
  2. If you define additionally multiboxonly:true: http://www.ok-soft-gmbh.com/jqGrid/DataToMultiSelect3.htm. It seems to me that this behavior is what you need.
  3. If you define additionally multikey:"ctrlKey": http://www.ok-soft-gmbh.com/jqGrid/DataToMultiSelect4.htm. In the case the row will be selected or deselected only if Ctrl are pressed.

If I understand your question correctly you should define both multiselect:true and multiboxonly:true to receive the behavior which you like.

If I misunderstood your question and you meaned something other please describe this in other words based on on of the above examples.

Stutter answered 15/9, 2010 at 16:16 Comment(2)
thanks! @Stutter ...multiboxonly:true means I cannot hide the checkbox ..since I am hiding my multiselect checkbox using ('hidecol','cb')..can it be possible when hiding the checkbox?Mumbletypeg
I am able to achieve using beforeSelectRow like beforeSelectRow: function (rowid, e) { if (!e.ctrlKey) { $("#list10").resetSelection(); } return true; } and just setting multiselect:true.....let me know if I am doing anything wrongMumbletypeg
O
0

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.

Orthoclase answered 27/6, 2017 at 13:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.