[英]jqgrid inline editing: dynamically set column editable properly of another column
在內聯編輯期間更改特定列的值時,我想動態更改同一行另一列的可編輯屬性值。 以下是我的代碼的一部分:
{ name: "admin", width:250, editable:<?php echo $owner; ?>, edittype:"custom", editoptions: {
custom_element: myelem,
custom_value:myvalue,
dataEvents: [{
type: 'change',
fn: function (e) {
var $this = $(e.target), $td, rowid;
var radSel = $(e.target).val(); //alert(radSel);
if(radSel == "No"){
if ($this.hasClass("FormElement")) {
$("#request").prop("editable", true);
} else {
//alert("you are here!!");
var row = $this.closest('tr.jqgrow');
var rowId = row.attr('id'); //alert(rowId);
$("#" + rowId + '_request').prop("editable", true);
}
}
}
}]
}},
{ name: "request", width: 100},
......
function myelem (value, options) {
var radio1 = document.createElement('input');
radio1.id = 'radY';
radio1.type = 'radio';
radio1.name = 'appr';
radio1.value = 'Yes';
if(value.match(/^Yes.*/)){ radio1.checked = true; }
var radio2 = document.createElement('input');
radio2.id = 'radN';
radio2.type = 'radio';
radio2.name = 'appr';
radio2.value = 'No';
if(value.match(/^No.*/)){ radio2.checked = true; }
var label1 = document.createElement('label');
label1.setAttribute('for', radio1.id);
label1.innerHTML = 'Yes';
var label2 = document.createElement('label');
label2.setAttribute('for', radio2.id);
label2.innerHTML = 'No';
var container = document.createElement('div');
container.appendChild(radio1);
container.appendChild(label1);
container.appendChild(radio2);
container.appendChild(label2);
return container;
}
function myvalue(elem, operation, value) {
if(document.getElementById('radY').checked) {return "Yes";}
else if(document.getElementById('radN').checked) {return "No";}
else {return ""; }
}
當我將單選按鈕更改為“否”時,它確實進入了if循環(在dataEvents下),但“ request”列上的editable屬性未動態設置為true。 任何幫助,不勝感激。 謝謝。
開始編輯之前 ,jqGrid將使用editable
屬性。 如果要防止動態編輯,則必須在相應的現有編輯字段上設置禁用或readonly
屬性/屬性 ,而不是設置editable
屬性。
此外,您似乎為自定義編輯字段分配了修訂id
屬性( 'radN'
, 'radY'
)。 這很危險,因為您可以擁有id
重復項。 內聯編輯使您可以同時編輯更多行。 在這種情況下,將創建兩個具有相同ID的自定義編輯元素,您將遇到問題。 我建議您另外在<label>
內設置<input>
<label>
。 在這種情況下,您將不需要任何id
或for
屬性。 嘗試
<label><input type="radio" name="appr" checked="checked" value="Yes"/>Yes</label>
<label><input type="radio" name="appr" value="No"/>No</label>
您可以通過單擊標簽來檢查單選按鈕。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.