【发布时间】:2023-03-29 12:52:01
【问题描述】:
我的 JqGrid 每行都带有 RadioButton,就像这样。
...
{ name: 'select', label: 'select', width: 50, formatter:radio}
无线电格式化程序的功能:
function radio(value, options, rowObject){
var radioHtml = '<input type="radio" value=' + value + ' name="radioid" />';
return radioHtml;
}
当我尝试从 jqgrid 中选择单行时,即仅使用此功能选择的单选按钮:
$(function () {
$("#<%=editButton.ClientID%>").click(function () {
var ids = $("#table").jqGrid('getCol', 'select', true);
alert(ids)
for (var i = 0; i < ids.length; i++) {
//alert(ids[i].id)
if (ids[i].id != '') {
var idx = $("#table").jqGrid('getCell', ids[i].id, 'select');
}
// alert(idx);
}
});
});
我正在获取网格中可用的所有行,而不是单个选定的行。
如果格式化程序是复选框,但不能用于收音机,则相同的功能效果很好。有什么遗漏吗?
更新:
colModel: [
{ name: 'select', label: 'select', width: 50,
formatter: function radio(cellValue, option) {
return '<input type="radio" name="radio_' + option.gid + '" />';
}
},
{ name: 'code', label: 'Branch Code', width: 250 },
{ name: 'name', label: 'Branch Name', width: 250 },
{ name: 'status', label: 'Group Status', width: 250 },
],
函数点击处理程序:
$("#<%=editButton.ClientID%>").click(function () {
alert('M');
var $selRadio = $('input[name=radio_' + $table[0].id + ']:checked'), $tr;
alert('I');
if ($selRadio.length > 0) {
$tr = $selRadio.closest('tr');
if ($tr.length > 0) {
alert("The id of selected radio button is " + $tr.attr('id'));
}
} else {
alert("The radio button is not selected");
}
});
【问题讨论】: