我正在使用Oleg的suggestion来使用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 = 8
和buttonNames = {8:'Add',9:'Edit',10:'Remove',11:'Details'}
代码。在您的代码中,您可以将警报替换为相应的函数调用。
问题是我的网格也是可排序的 - (我在网格上使用了sortableRows
方法)。如果用户点击单元格时即使移动鼠标,也不会触发事件(可排序的事件)。
这在大多数情况下是可取的 - 但是,我认为可以解决这个问题的方法是以某种方式将列从“句柄”中排除以拖动(排序)行,并让我的事件在这些列上触发。我似乎无法弄清楚如何做到这一点!任何帮助非常感谢:)
这完美的作品!再次感谢你)! – icats 2011-05-20 22:04:20
@icats:不客气! – Oleg 2011-05-21 06:02:39