jqGrid - 当我点击网格中的另一个复选框时,选中多选复选框

时间:2016-04-20 06:31:35

标签: javascript jquery checkbox jqgrid

在我的网格功能中,每当我点击网格中的任何复选框时,我都希望选中多选复选框。 这是我的网格代码:

var el = jQuery("#GridId"),
    gridWidth = calculateWidth(null,null,el);
el.jqGrid({
    datatype: 'local' ,
    caption: localeHolder['List_View'],
    hidegrid : false,
    mtype : 'POST',
    autowidth: true,
    height: calculateHeight(el),
    width:gridWidth,
    rowNum: 30,
    colNames:[localeHolder['T1'],localeHolder['T2'],localeHolder['T3'],localeHolder['T4'],localeHolder['T5']],
    colModel:[
              {name:'t1',index:'t1.id1',searchtype:"String", align:"left",hidden:false,width:calculateWidth(20,gridWidth,null),
                      searchtype:"String", searchoptions:{sopt:['eq','ne','le','lt','gt','ge']}},
              {name:'t2',index:'t1.id2',searchtype:"String", sortable:true,width:calculateWidth(30,gridWidth,null),
                      //formatter:function (cellvalue, options, rowObject){ return formatTypeRequiredSpecialCharacterNotAllowedTextBox(options, rowObject,'t2',50,true,"onClickEventOnGrid("+ options.rowId +")");}
                      },
              {name:'t3',index:'t1.id3',searchtype:"String", align:"left", sortable:true,width:calculateWidth(60,gridWidth,null),
                      searchtype:"String",searchoptions:{sopt:['cn','bw','ew','eq','ne']}},
              {name:'t4',index:'t1.id4', /*align:"center",*/ sortable:true,width:calculateWidth(20,gridWidth,null),
                          formatter:function (cellvalue, options, rowObject){ return formatTypeCheckBox(options, rowObject,'t2',true,"onClickEventOnGrid("+ options.rowId +")");},
                          searchtype:"String",searchoptions:{sopt:['cn','bw','ew','eq','ne']}},
              {name:'t5',index:'t1.id5', /*align:"center",*/ sortable:true,width:calculateWidth(20,gridWidth,null),
                          formatter:function (cellvalue, options, rowObject){ return formatTypeCheckBox(options, rowObject,'t2',true,"onClickEventOnGrid("+ options.rowId +")");},
                          searchtype:"String",searchoptions:{sopt:['cn','bw','ew','eq','ne']}}
              ],
    multiselect: true,
    pager: '#GridPagerId',
    sortname: 't1',
    sortorder: "asc", 
    viewrecords : true,
    emptyrecords : localeHolder['no_result_found'],
    loadonce : false,
    altRows:true,
    altclass:'altRow',
    hoverrows: true,
    ignoreCase: true,
    gridview: true,

    onPaging: function(pgButton) {
        return onPageEventInGrid("GridId","GridPagerId",pgButton);
    },
    beforeSelectRow: function(rowid, e){
        return(true);
    },
    onSelectRow:function() {

        return(true);
    },
    onSortCol: function () {

    },
    beforeRequest : function(){

    },
    loadComplete : function() {


    },
    loadError : function(error) {
        openErrorDialog(GRID_ERROR);
    },
    jsonReader : {
        root : "gridRecords",
        page : "page",
        total : "total",
        records : "records",
        repeatitems : false,
        cell : "cell"
    }

所以每当我点击T4或T5时。应该选中Multislect复选框吗?

1 个答案:

答案 0 :(得分:0)

可以在Grid的onSelect函数上完成。 我们只需要获取该ID以进行勾选/检查。

  onSelectRow:function(rowId, status, e) {
        var rowData = $('#GridId').jqGrid ('getRowData', rowId); 
        if($("#xxx_GridId_" + rowId).is(':checked')) {
            $("#ChkBoxId" + rowData.t2).attr("checked", true);
        }
        return(true);

其中,xxx_gridId + rowId结合使用该多选复选框的“id”。