jqGrid中multiselect: true 操作checkbox

在jqGrid中设置multiselect: true可以实现全选的操作,但怎么设置被选中的checkbox里面的值呢,做法如下:
jQuery("#listTable").jqGrid({
   url: 'queryList.do',
   datatype: 'json',
   colNames: ['','编号','姓名'],
   colModel: [
               { 
                 name: 'MY_ID',
                 index: 'MY_ID',
                 sortable: false,
                 width: '0%',
                 hidden:true
               },
               {
                 name: 'MY_NO',
                 index:'MY_NO',
                 sortable: false,
                 align:'center',
                 width:'10%'
               },
              {
                 name: 'NAME',
                 index:'NAME',
                 sortable: false,
                 align:'center',
                 width:'10%'
              }
            ],
            page: 1,
            rowNum: 10,
            rowList: [10, 20, 30],
            pager: '#listPage',
            multiselect: true,
            sortname: 'MY_NO',
            viewrecords: true,
            sortorder: "desc",
            jsonReader: {
                repeatitems: false
            },
            width: "100%",
            height: '100%',
            gridComplete: function() {
                var rowIds = jQuery("#listTable").jqGrid('getDataIDs');
                for(var k=0; k                   var curRowData = jQuery("#listTable").jqGrid('getRowData', rowIds[k]);
                   var curChk = $("#"+rowIds[k]+"").find(":checkbox");
                   curChk.attr('name', 'checkboxname');   //给每一个checkbox赋名字
                   curChk.attr('value', curRowData['MY_ID']);   //给checkbox赋值
                   curChk.attr('title', curRowData['NAME'] );   //给checkbox赋予额外的属性值

                   //curChk.attr('checked', 'true');   //设置所有checkbox被选中
                }
 
                //下面的代码顺序不能变(这是页面上所有行被真选中[所有行被黄色])
                //$("#cb_listTable").attr("checked", true);
                //$("#cb_listTable").click();   //input框
                //$("#jqgh_listTable_cb").click();   //div标签
                //$("#listTable_cb").click();   //th标签
            }
});

加载完列表后获取被选中的checkbox的值及其属性值的做法如下:
var checkedVals = new Array();
var checkedTitles = new Array();
$(":checkbox[name=checkboxname][checked]").each(function(){
      checkedVals.push($(this).val());
      checkedTitles.push($(this).attr("title"));
});
for(var p=0; p    alert(checkedVals[p]);
    alert(checkedTitles[p]);
}

--------------------------------------------------------------------------------------------------
让查询列表中按指定条件被默认选中或灰掉checkbox的做法如下:
jQuery("#listTable").jqGrid({
   url: 'queryList.do',
   datatype: 'json',
   colNames: ['','编号','姓名'],
   colModel: [
               { 
                 name: 'MY_ID',
                 index: 'MY_ID',
                 sortable: false,
                 width: '0%',
                 hidden:true
               },
               {
                 name: 'MY_NO',
                 index:'MY_NO',
                 sortable: false,
                 align:'center',
                 width:'10%'
               },
              {
                 name: 'NAME',
                 index:'NAME',
                 sortable: false,
                 align:'center',
                 width:'10%'
              }
            ],
            page: 1,
            rowNum: 10,
            rowList: [10, 20, 30],
            pager: '#listPage',
            multiselect: true,
            multiboxonly: true,
            sortname: 'MY_NO',
            viewrecords: true,
            sortorder: "desc",
            jsonReader: {
                repeatitems: false
            },
            width: "100%",
            height: '100%',
            gridComplete: function() {
                var rowIds = jQuery("#listTable").jqGrid('getDataIDs');
                for(var k=0; k                   var curRowData = jQuery("#listTable").jqGrid('getRowData', rowIds[k]);
                   if(curRowData.MY_NO == '123456'){
                        $("#listTable").find("input[id='jqg_" + rowIds[k] +
                                                                      "']").val(curRowData.MY_ID);
                        if(curRowData.NAME=='shihuan'){
                            $("#listTable").find("input[id='jqg_" + rowIds[k] +
                                                                      "']").attr("checked", true);
                        }
                    }else{
                        $("#listTable").find("input[id='jqg_" + rowIds[k] +
                                                                      "']").val(curRowData.MY_ID);
                        $("#listTable").find("input[id='jqg_" + rowIds[k] + "']").attr("checked",
                                                                                            true);
                        $("#listTable").find("input[id='jqg_" + rowIds[k] + "']").attr("disabled",
                                                                                            true);
                    }
                }
            }
            onSelectAll:function(rowid, status) { //rowid 数组
                var ids = jQuery("#listTable").jqGrid('getDataIDs');
                for (var i=0; i                    var cl = ids[i];
                    var curRowData = jQuery("#listTable").jqGrid('getRowData', cl);
                    var ckt = $("#listTable").find("input[id='jqg_" + cl + "']").attr("disabled");
                    if(ckt){
                        $("#listTable").find("input[id='jqg_" + cl + "']").attr("checked", true);
                    }
                }
            },
            beforeSelectRow:function(rowid, e){
                //alert(rowid);   //rowid的值是checkbox的value值
                return false;
            }
});
--------------------------------------------------------------------------------------------------
jqGrid被重新载入的做法如下:
function gridReload() {
    jQuery("#listTable").jqGrid('setGridParam', {
                //url:'../../../com/shihuan/search.do',
                //postData: transferFormElementsToObject('theForm'),
                postData: {"message":msval},
                page:1
            }).trigger("reloadGrid");
}

你可能感兴趣的:(jqGrid中multiselect: true 操作checkbox)