2011-05-20 60 views
1

我正在使用Olegsuggestion来使用beforeSelectRow事件来处理单击在我的网格中的单元格。JQGrid:'beforeSelectRow'和'sortableRows' - 排除列可拖动?

奥列格在他的答案代码(矿正是模仿):

你可以这样定义以下

{ 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方法)。如果用户点击单元格时即使移动鼠标,也不会触发事件(可排序的事件)。

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

回答

2

,如果你添加下面的附加代码

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的排序功能,如果鼠标会在动作的按钮。因此,您只能在另一列对行进行排序。

您可以看到修改的演示here

+0

这完美的作品!再次感谢你)! – icats 2011-05-20 22:04:20

+0

@icats:不客气! – Oleg 2011-05-21 06:02:39

相关问题