我有這樣每行每行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