[英]Prevent jqGrid from entering edit cell using beforeCellEdit event?
在CellEdit之前捕獲事件時,是否可以通過某種方式阻止單元格進入編輯模式?
beforeEditCell: function (rowid, cellname, value, irow, icol) {
if (cellname != 'aSpecificCol')
return;
var grid = $("#grid");
if (aCondition == "something")
grid.setColProp('aSpecificCol', { editable: false });
else
grid.setColProp('aSpecificCol', { editable: true });
}
事件觸發,但column屬性的設置似乎未更改編輯模式。
在編輯過程中,將調用beforeEditCell
方法。 它的存在主要是為了在新創建的輸入或選擇元素中進行一些初始化。
如果你需要防止一些細胞從細胞編輯模式編輯我岑建議你要么設置"not-editable-cell"
的細胞類有時之前(例如,在cellattr
或loadComplete
),或使用beforeSelectRow
返回false
一些細胞。 它在beforeSelectRow
返回false之前將不編輯該單元格。
beforeSelectRow: function (rowid, e) {
var $td = $(e.target).closest("td"), iCol = $.jgrid.getCellIndex($td[0]);
if (/* test some rules here */) {
return false; // prevent selection and so the editing of the cell
}
}
正確,您需要找到另一種選擇,因為beforeEditCell
僅提供一種在編輯單元格之前執行更多代碼的方法。 從grid.celledit.js
:
if ($.isFunction($t.p.beforeEditCell)) {
$t.p.beforeEditCell.call($t, $t.rows[iRow].id,nm,tmp,iRow,iCol);
}
但是,看來您應該能夠調用restoreCell
來阻止編輯模式:
restoreCell
iRow,iCol
使用索引列iCol中的行索引iRow(不與rowid混合)恢復單元格的編輯內容
例如:
beforeEditCell: function (rowid, cellname, value, irow, icol) {
var grid = $("#grid");
if (cellname != 'aSpecificCol') {
grid.jqGrid("restoreCell", irow, icol);
return;
}
如果這不起作用,則可以嘗試將此代碼添加到afterEditCell
事件中,這可能是更合適的位置。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.