我有这样每行每行JqGrid与RadioButton。jqGrid单选按钮选择单行
...
{ 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 i.ee.,单选按钮其仅使用该功能选择的singlerow:
$(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);
}
});
});
正在获取网格中的所有行,而不是单个选定的行。
如果格式化程序是复选框但不是收音机,相同的函数效果很好。有什么遗漏吗?
UPDATE:
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 },
],
功能Click处理程序:
$("#<%=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");
}
});
您好奥列格,没有成功这条线心不是执行变量$ selRadio = $( '输入[名称= radio_' + $表[0] + .ID ']:检查'),$ TR; “表”是我的网格ID。 – 2011-12-18 16:33:39
@Samuel:你的意思是“这条线没有执行”?点击句柄是不是被调用,或者你在行中得到一个异常,或者'$ selRadio'返回总是带有'length' = 0的对象?你使用了哪个'formatter'?你是否在单选按钮的名称中包含了'option.gid'?你应该把我的演示和青春完全比较。我的演示在你的环境中工作吗?如果它是工作,你应该找到你的代码的区别。 – Oleg 2011-12-18 18:12:16
嗨奥列格,已更新我提出的更改你的问题..对不起,没有描述完整的错误。该代码没有执行后提到的线没有例外,名词定义的值。我的意思是我在线路前后放置了一个简单的警报。 – 2011-12-18 18:19:42