JQGrid onselectrow 事件 - 自定义多选

发布于 2024-09-18 17:36:48 字数 1113 浏览 4 评论 0原文

我经常使用 JQGrid,并将其推荐给所有人。 我不太喜欢的一个功能是内置的多选功能,它不使用 Shift 和 Ctrl 等特殊键,不给您太多控制权并强制显示复选框。

我想实现我自己的多重选择,如下所示: 在 onSelectRow- 检查是否按住 Shift 或 Ctrl 键,将行 id 添加到数组中并在网格中选择它。如果没有保留,则清除数组并添加新的行 ID 并在网格中选择它。

这很容易实现,除了我需要 onSelectRow 中的一个事件来检查按键是否被按住。我不想在主文档本身上附加 keydown 和 keyup 事件。

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

            }
            else {

            }
}

问候, 拜伦·科布.

编辑:解决方案 -

根据 Olegs 的输入,我完成了以下操作。

  1. 在网格定义中设置 multiselect: true
  2. 通过设置 $("#myGrid").jqGrid('hideCol', 'cb' 隐藏 gridComplete 中的复选框列);
  3. 在选择之前我自己检查了 ctrl 键(不使用多键:“ctrlKey”),如果没有按下 ctrl 键则清除选择。
  4. 稍后在需要时使用选择数组 - var SelectedRows = $("#myGrid").jqGrid('getGridParam', 'selarrrow');

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

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;
        },

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

分开我的手 2024-09-25 17:36:48

从3.5.3版本开始 jqGrid支持beforeSelectRow 事件,其中包含您需要的事件,该事件将是在onSelectRow之前调用。

可能是使用 jqGrid 的 multikey 选项并隐藏名为“cb”的伪列

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

(cb - 组合框,请参阅 http://www.trirand.com/blog/?page_id=393/help/multiselect-without-checkboxes-1/)将帮助您在jqGrid中实现row的行为选择您想要的。

更新:我想您也知道 $("#mygrid").jqGrid('getGridParam','selarrrow') 可用于获取 id 数组所有当前选定的行,但为了确保我也插入信息。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文