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<rowIds.length; 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賦予額外的屬性值json

                   //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<checkedVals.length; 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<rowIds.length; 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<ids.length; 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"); }
相關文章
相關標籤/搜索