JQGrid:'beforeSelectRow'和'sortableRows' - 排除列可拖动? [英] JQGrid: 'beforeSelectRow' and 'sortableRows' - exclude column from being draggable?

查看:22
本文介绍了JQGrid:'beforeSelectRow'和'sortableRows' - 排除列可拖动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Olegsuggestion 使用 beforeSelectRow 事件来处理对我网格中单元格的点击.

奥列格在他的回答中的代码(我的完全模仿):

<块引用>

您可以使用如下按钮定义列

{ name: 'add', width: 18, sortable: false, search: false,格式化程序:函数(){return "<span class='ui-icon ui-icon-plus'></span>"}}

<块引用>

在上面的代码中,我确实使用了 jqGrid 的自定义格式化程序,但没有任何事件绑定.代码

beforeSelectRow: function (rowid, e) {var iCol = $.jgrid.getCellIndex(e.target);if (iCol >= firstButtonColumnIndex) {alert("rowid="+rowid+"
按钮名称:"+buttonNames[iCol]);}//如果单击按钮,则阻止行选择返回(iCol >= firstButtonColumnIndex)?假:真;}

<块引用>

其中 firstButtonColumnIndex = 8buttonNames = {8:'Add',9:'Edit',10:'Remove',11:'Details'}.在您的代码中,您可以将警报替换为相应的函数调用.

问题是我的网格也是可排序的——(我在我的网格上使用 sortableRows 方法).如果用户在单击单元格时稍微移动鼠标,则永远不会触发 beforeSelectRow 事件(可排序事件是).

这在大多数情况下都是可取的-但是,我认为解决此问题的方法是以某种方式将列排除在句柄"之外以拖动(排序)行并让我的 onSelectRow 事件触发这些列.我似乎无法弄清楚如何做到这一点!非常感谢任何帮助:)

解决方案

添加以下附加代码即可解决问题

var grid = $('#list'), tbody = $("tbody:first",grid[0]), ptr, td;grid.bind('mouseover',function(e) {var iCol = $.jgrid.getCellIndex(e.target);if (iCol >= firstButtonColumnIndex) {tbody.sortable("禁用");} 别的 {tbody.sortable("启用");}});

如果鼠标悬停在操作按钮上,代码将禁用 jqGrid 的可排序功能.因此,您将只能对另一列中的行进行排序.

您可以在这里查看修改后的演示.

I am using Oleg's suggestion to use the beforeSelectRow event to handle clicks on cells within my grid.

Oleg's code in his answer (which mine exactly mimics):

You can define the columns with buttons like following

{ name: 'add', width: 18, sortable: false, search: false, 
formatter:function(){
    return "<span class='ui-icon ui-icon-plus'></span>"
}}

In the code above I do use custom formatter of jqGrid, but without any event binding. The code of

beforeSelectRow: function (rowid, e) {
        var iCol = $.jgrid.getCellIndex(e.target);
        if (iCol >= firstButtonColumnIndex) {
        alert("rowid="+rowid+"
Button name: "+buttonNames[iCol]);
    }

    // prevent row selection if one click on the button
    return (iCol >= firstButtonColumnIndex)? false: true;
}

where firstButtonColumnIndex = 8 and buttonNames = {8:'Add',9:'Edit',10:'Remove',11:'Details'}. In your code you can replace the alert to the corresponding function call.

The problem is that my grid is also sortable- (I use the sortableRows method on my grid). If the user is moving the mouse even a little when clicking the cell, the beforeSelectRow event is never triggered (the sortable event is).

This is desirable in most situations- however, I think what would fix this is to somehow exclude columns from being 'handles' to drag (sort) the row and let my onSelectRow event trigger on those columns. I just can't seem to figure out how to do this! Any help is extremely appreciated :)

解决方案

You can fix the problem if you add the following additional code

var grid = $('#list'), tbody = $("tbody:first",grid[0]), ptr, td;
grid.bind('mouseover',function(e) {
    var iCol = $.jgrid.getCellIndex(e.target);
    if (iCol >= firstButtonColumnIndex) {
        tbody.sortable("disable");
    } else {
        tbody.sortable("enable");
    }
});

the code will be disable sortable feature of jqGrid if the mouse will be over the actions buttons. So you will be able to sort the rows only in another column.

You can see the modified demo here.

这篇关于JQGrid:'beforeSelectRow'和'sortableRows' - 排除列可拖动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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