【问题标题】:JQGrid: 'beforeSelectRow' and 'sortableRows' - exclude column from being draggable?JQGrid:'beforeSelectRow'和'sortableRows' - 排除列可拖动?
【发布时间】:2011-08-29 19:08:08
【问题描述】:

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

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

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

{ name: 'add', width: 18, sortable: false, search: false, 
formatter:function(){
    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+"\nButton name: "+buttonNames[iCol]);
    }

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

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

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

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

【问题讨论】:

    标签: jquery jqgrid


    【解决方案1】:

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

    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");
        }
    });
    

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

    可以看到修改后的demohere

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-23
      • 2014-01-17
      • 1970-01-01
      • 1970-01-01
      • 2018-04-06
      • 2011-03-22
      • 1970-01-01
      • 2013-10-26
      相关资源
      最近更新 更多