まず、dataEvents
編集要素の要素にコールバックを登録できます。コールバックの内部は、this
バインドされる DOM 要素に初期化されます。したがって、ハンドラー$(this)
内では、グリッドではなく要素のラッパーになります。の使い方が間違っています。change
<select>
$(this).setColProp
追加/編集フォームの一部の入力フィールドを無効にするには、すべての入力要素がの対応する列のプロパティid
の値のように同じになるという事実を利用できます。したがって、入力を無効にする必要がある場合は、要素のプロパティを次のように設定できますname
colModel
cntrct_id
disabled
true
id="cntrct_id"
{
name: 'type_cd',
edittype: 'select',
editoptions: {
dataUrl: 'functions.php',
dataEvents: [{
type: 'change',
fn: function (e) {
// disable input/select field for column 'cntrct_id'
// in the edit form
$("#cntrct_id").prop("disabled", true);
}
}]
}
}
editoptions
が既存の編集モード (フォーム編集、インライン編集、セル編集) に使用されることを理解することが重要です。すべての編集モードをサポートするコードを書きたい場合は、dataEvents
編集モードを検出し、編集フィールドの他の ID を少し使用する必要があります。コード(テストされていません)は次のようになります
{
name: 'type_cd',
edittype: 'select',
editoptions: {
dataUrl: 'functions.php',
dataEvents: [{
type: 'change',
fn: function (e) {
var $this = $(e.target), $td, rowid;
// disable input/select field for column 'cntrct_id'
if ($this.hasClass("FormElement")) {
// form editing
$("#cntrct_id").prop("disabled", true);
} else {
$td = $this.closest("td");
if ($td.hasClass("edit-cell") {
// cell editing
// we don't need to disable $("#cntrct_id")
// because ONLY ONE CELL are edited in cell editing mode
} else {
// inline editing
rowid = $td.closest("tr.jqgrow").attr("id");
if (rowid) {
$("#" + $.jgrid.jqID(rowid) + "_cntrct_id")
.prop("disabled", true);
}
}
}
}
}]
}
}
最後の発言。propメソッドをサポートしていない古いバージョンの jQuery (jQuery 1.6 より前) をまだ使用している場合は、代わりにattrを使用する必要があります。