views:

378

answers:

1

Hey there!

I've been working with JQGrid a lot, and would recommend it to everyone. The one feature I don't really like is the built in multiselect which doesnt use special keys like shift and ctrl, doesnt give you much control and forces checkboxes to be shown.

I would like to implement my own multiselect as follows: In onSelectRow- check if shift or ctrl is held add the row id to an array and select it in the grid. if none are held, clear the array and add the new row id and select it in the grid.

This is simple enough to implement, except i need an event in the onSelectRow to check if the keys are held. I would prefer not to attach a keydown and keyup event on the main document itself.

onSelectRow: function (id) {
            event=???
            if (!event.shiftKey && !event.ctrlKey) {

            }
            else {

            }
}

Regards, Byron Cobb.

EDIT: Solution -

Following Olegs input, I have done the following.

  1. Set multiselect: true in the grid definition
  2. Hidden the checkbox column in gridComplete by setting $("#myGrid").jqGrid('hideCol', 'cb');
  3. Checked for the ctrl key myself(not using multikey:"ctrlKey") before the select and clearing the selection if no ctrl key is pressed.
  4. Later using the selection array when needed - var SelectedRows = $("#myGrid").jqGrid('getGridParam', 'selarrrow');

beforeSelectRow: function (rowid, e) {
            if (!e.ctrlKey) {
                $("#myGrid").resetSelection();
            }
            return true;
        },
+1  A: 

Since the version 3.5.3 jqGrid support beforeSelectRow event which has event which you need and which will be called before onSelectRow.

Probably the usage of multikey option of jqGrid and hiding of the pseudo-column with the name "cb"

$("#mygrid").jqGrid('hideCol','cb');

(cb - combo-boxes, see http://www.trirand.com/blog/?page_id=393/help/multiselect-without-checkboxes-1/) will help you to implement in jqGrid the behavior of row selection which you want.

UPDATED: I suppose you also know that $("#mygrid").jqGrid('getGridParam','selarrrow') can be used to get the array of ids of all currently selected rows, but to be sure I insert the information also.

Oleg
@Oleg - Thanks again. I've got my version working in the beforeSelectRow. Trying the default multiselect with multikey:"ctrlKey" only calls the onSelectRow if ctrl is held down - should it not clear the multiselect and start a new selection?
Byron Cobb
In my beforeSelectRow I've set it to always return true, but with multiselect and multikeys (when ctrl isnt held down) still doesnt call onSelectRow
Byron Cobb
@Byron Cobb: Congratulations! It seems to me that the behavior which you implemented could be interesting for other users of jqGrid. You can append your question with the code to share the solution with other. Moreover you can post it also in http://www.trirand.com/blog/?page_id=393/feature-request/ and probably it will be a part of the next version of jqGrid.
Oleg
@Oleg - Following your input, it seems pretty simple but i've added the solution to my question anyway. Thanks again.
Byron Cobb
@Byron Cobb: Very good! Nevertheless the most problems appears not once. If the solution described more detailed or there are a demo page which show "how to..." it helps many other people with the same problem. Best regards.
Oleg