开发者

JQGrid onselectrow events - custom multiselect

开发者 https://www.devze.com 2023-01-15 16:15 出处:网络
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 giv

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 p开发者_开发知识库ressed.
  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;
        },


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号