我有需要在编辑时行的一列单选按钮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功能设置。 它激发得到radiovalue功能,而当选择了行创建单选按钮。 任何帮助,这样我可以设置一个值的单选按钮?
谢谢