我有一個jqGrid,它需要在編輯時在一行的列中有單選按鈕。 以下是我的代碼:jqGrid自定義編輯類型(單選按鈕列)自定義元素不發射設置事件編輯
function BindPreclosingDocs(response) {
var previouslyselectedRow;
var preclosingtable = $('#preclosing');
preclosingtable.jqGrid({
datatype: 'jsonstring',
datastr: JSON.stringify(response.ServiceModel),
colNames: ['', 'Documents Received', 'Comments', 'SubDocument', 'NA'],
colModel: [
{ name: 'Documents', index: 'Documents', align: 'left', sortable: false, editable: false, width: 240 },
{ name: 'DocsReceived', index: 'DocsReceived', align: 'center', sortable: false, editable: true, edittype: 'checkbox', editoptions: { value: "True:False" }, formatter: "checkbox", width: 140 },
{ name: 'Comments', index: 'Comments', align: 'center', sortable: false, editable: true, edittype: "textarea", editoptions: { rows: "3", cols: "16" }, width: 180 },
{ name: 'SubDocument', index: 'SubDocument', editable: false, width: 1 },
{ name: 'NA', index: 'NA', editable: true, formatter: 'dynamicText', width: 150, edittype: 'custom', editoptions: { custom_element: radioelem, custom_value: radiovalue} }
],
rowNum: response.ServiceModel.PreClosing.length,
pager: '#preclosingpagerdiv',
viewrecords: true,
sortorder: "asc",
sortname: 'Documents',
jsonReader: {
root: "PreClosing",
repeatitems: false,
id: 'ConfigId'
},
shrinkToFit: false,
height: 'auto',
grouping: true,
groupingView: {
groupField: ['SubDocument'],
groupColumnShow: [false],
plusicon: 'ui-icon-circle-triangle-s',
minusicon: 'ui-icon-circle-triangle-n'
},
loadComplete: function() {
HideGroupHeaders(this);
},
onSelectRow: function (id) {
preclosingtable.jqGrid('saveRow', previouslyselectedRow, false, 'clientArray');
previouslyselectedRow = SetJQGridRowEdit(id, previouslyselectedRow, preclosingtable);
}
});
preclosingtable.setGridWidth('710');
};
//RowSelect
function SetJQGridRowEdit(id, previousid, grid) {
if (id && id !== previousid) {
grid.jqGrid('restoreRow', previousid);
grid.jqGrid('editRow', id, true);
previousid = id;
return previousid;
}
};
//Build radio button
function radioelem(value, options) {
var receivedradio = '<input type="radio" name="receivednaradio" value="R"';
var breakline = '/>Received<br>';
var naradio = '<input type="radio" name="receivednaradio" value="N"';
var endnaradio = '/>NA<br>';
if (value == 'Received') {
var radiohtml = receivedradio + ' checked="checked"' + breakline + naradio + endnaradio;
return radiohtml;
}
else if (value == 'NA') {
var radiohtml = receivedradio + breakline + naradio + ' checked="checked"' + endnaradio;
return radiohtml;
}
else {
return receivedradio + breakline + naradio + endnaradio;
}
};
function radiovalue(elem, operation, value) {
if (operation === 'get') {
return $(elem).val();
} else if (operation === 'set') {
if ($(elem).is(':checked') === false) {
$(elem).filter('[value=' + value + ']').attr('checked', true);
}
}
};
我格式化和unformatter代碼如下我有
dynamicText: function (cellvalue, options, rowObject) {
if (cellvalue == 'R') {
return 'Received';
}
else if (cellvalue == 'N') {
return 'NA';
}
else {
return '';
}
}
$.extend($.fn.fmatter.dynamicText, {
unformat: function (cellValue, options, elem) {
debugger;
var text = $(elem).text();
return text === ' ' ? '' : text;
}
});
的問題是,當我選擇一個行和檢查的編輯按鈕,它不會放火在無線電價值功能。當選中一行時,它會創建單選按鈕,並觸發radiovalue函數。任何幫助,以便我可以設置一個值單選按鈕?!
謝謝
感謝Oleg的回覆。我沒有在這裏使用窗體edititng。我正在編輯選定行上的內嵌行。我遇到的問題是,一旦我選擇了一行,我就會得到單選按鈕組。現在我選擇值爲'N'的第二個單選按鈕。當選擇其他行時,我保存到clientArray,我期望以前編輯過的行列將NA列值更新爲NA。但它將其更新爲「收到」。即使我沒有從單選按鈕中選擇任何選項,它也會將其更新爲「已收到」。 – fcmaine
@SrinivasPotluri:不客氣!你的問題是「爲什麼自定義元素不能在編輯時觸發設置事件」。我回答你,它只是在表單編輯中被解僱。你在上次評論中提出的問題是*新問題*。我想你有一些問題,因爲你調用'restoreRow'而不是'saveRow',或者只是因爲你在編輯模式中使用單選按鈕而不是使用自定義格式化程序。要理解這個問題,您應該發佈帶有測試數據**的新問題**,以及您在何處描述詳細的測試用例,預期結果和演示結果。 – Oleg
我也在jsfiddle上添加了代碼示例[link](http:// jsfiddle。net/srinivaspotluri/xx7Jg/3 /) – fcmaine