jqGrid中实现radiobutton的两种做法

http://blog.sina.com.cn/s/blog_4f925fc30102e27j.html   jqGrid中实现radiobutton的两种做法

--------------------------------------------------------------------------------------------------

 

第一种:
colModel: [
                {
                    name: 'MY_ID',
                    index: 'MY_ID',
                    align: "center",
                    sortable: false,
                    width: '5%'
                },
                ...
          ],
gridComplete: function() {  //增加编辑按钮
                var ids = jQuery("#templist").jqGrid('getDataIDs');
                for (var i=0; i<ids.length; i++) {
                    var cl = ids[i];
                    var ret = jQuery("#templist").jqGrid('getRowData', cl);
                    bnEdt = "<input type='radio' name='myname' value='" +ret.MY_ID + "'
                                                              onclick='setmyval(" + cl + ");' />";
                    jQuery("#templist").jqGrid('setRowData', cl, {
                        MY_ID : bnEdt
                    });
                }
            }

--------------------------------------------------------------------------------------------------
第二种做法:
colModel: [
            { 
                name: 'MY_ID',
                index: 'MY_ID',
                sortable: false,
                align:'center',
                width: '8%',
                formatter:function(cellvalue, options, rowObject){
                    return "<input type='radio' name='myId' value='"+cellvalue+"' 
                                                onclick=\"radioSelect('myId', 'listTable')\" />";
                }
            },
          ]

--------------------------------------------------------------------------------------------------
点击某一行的时候radiobutton被选中的做法:
onSelectRow: function(ids) {
                  $($(this)[0]).find("input[name='myId']")[ids - 1].checked = true;
             }
【注】:上面$(this)[0]中的0代表当前被选中的radiobutton这一行,跟radiobutton在第几列没关系,关键是
        name='myId'这个名字要正确。
 
--------------------------------------------------------------------------------------------------
获取选中某一行的写法如下:
var selectedId = $("#templist").jqGrid("getGridParam", "selrow");
var rowdata = $("#templist").jqGrid("getRowData", selectedId);
alert(rowdata.questionno + " -- " + rowdata.questiondescription);
 
 

另外该博主的博客很不错!!!

 

posted @ 2016-06-14 11:24  wenlj2000  阅读(1023)  评论(0编辑  收藏  举报