jqGrid 多选 - 仅使用复选框限制行的选择 [英] jqGrid multiselect - limit the selection of the row only using the checkbox

查看:23
本文介绍了jqGrid 多选 - 仅使用复选框限制行的选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

早上好,我正在开发一个激活多选的 jqGrid.

Good morning, I'm working on a jqGrid that have the multiselection active.

我只需要使用 multisel 框来限制对行的选择,而不是通过单击行上的任何位置.那是因为我需要通过单击某些单元格上的链接来执行一些操作,并且我不会更改活动的多选.我试图设置 multiboxonly 属性,但这不是我需要的.我没有找到其他任何东西可以自定义网格的这个功能.

I need to limit the selection of the row only using the multisel box, not by clicking everywhere on the row. Thats's because I need to do some action by clicking links on some cells and I won't alter the active multiselection. I tried to set the multiboxonly property, but it's not what I need. I didn't find anything else to customize this function of the grid.

推荐答案

您可以控制根据您的自定义beforeSelectRow 事件处理程序.如果处理程序返回 true,则将选择该行.如果返回 false,则不会选择该行.

You can control on which click the row will be selected with respect of your custom beforeSelectRow event handler. If the handler return true, the row will be selected. If you return false the row will be not selected.

beforeSelectRow的第二个参数是事件对象e.target 是被点击的 DOM 元素.您可以使用 $(e.target).closest('td') 获取单击完成的单元格 (<td>).然后你可以使用 $.jgrid.getCellIndex 来获取单元格的索引行的内部.colModel 中的索引应指向包含复选框的cb"列.所以代码可能如下:

The second parameter of beforeSelectRow is event object, e.target is the DOM element which was clicked. You can get the cell (<td>) in which the click done with $(e.target).closest('td'). Then you can use $.jgrid.getCellIndex to get the index of the cell insido of the row. The index in the colModel should point to the 'cb' column which contain the checkboxes. So the code could be the following:

beforeSelectRow: function (rowid, e) {
    var $myGrid = $(this),
        i = $.jgrid.getCellIndex($(e.target).closest('td')[0]),
        cm = $myGrid.jqGrid('getGridParam', 'colModel');
    return (cm[i].name === 'cb');
}

您可以在这里查看相应的演示.

The corresponding demo you can see here.

这篇关于jqGrid 多选 - 仅使用复选框限制行的选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆