我正在使用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