簡體   English   中英

防止jqGrid使用beforeCellEdit事件進入編輯單元格?

[英]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"的細胞類有時之前(例如,在cellattrloadComplete ),或使用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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM