无法使用jqgrid在列中显示复选框

时间:2019-07-12 07:32:30

标签: javascript jqgrid

我想添加复选框列,以便用户可以选择所需的记录,我已经添加了将在jqGrid中显示复选框列的代码,但是无法显示出来,我的编码有什么问题?

我已经在loadcomplete,gridComplete,beforeSelectRow和onSelectAll中添加了代码,但是它不起作用。

...
<table id='A_Grid'></table>
<div id='A_GridPager'></div>
<script type='text/javascript'>
jQuery(document).ready(function($) {
   jQuery('#A_Grid').jqGrid({
        "hoverrows": true
        , "viewrecords": true
        , "jsonReader": {
            "repeatitems": false
            , "subgrid": {
                "repeatitems": false
            }
        }
        , "xmlReader": {
            "repeatitems": false
            , "subgrid": {
                "repeatitems": false
            }
        }
        , "gridview": true
        , "width": $(window).width() - 280
        //, "rownumbers": true
        , "rownumWidth": 35
        , "datatype": "json"
        , "url": "A_Data.php"
        , "editurl": "A_Data.php"
        , "cellurl": "A_GridData.php"
        , "caption": "產生HSBC"
        , "rowNum": 1000
        , "multiSort": false
        // , "sortname": "invcode"
        , "loadui": "block"
        , "altRows": true
        , "altclass": "custAltRowClass"
        , "autowidth": false
        , "mtype": "POST"
        , "multiselect": false
        , "toolbar": [true, "top"]
        , "height": $(window).height() - 550
        , "gridComplete": function() {
            if (typeof this.grid.fbDiv !== "undefined") {
                $(this.grid.fbDiv).css($(this.grid.bDiv).position());
            }
            if (typeof this.grid.fhDiv !== "undefined") {
                $(this.grid.fhDiv).css($(this.grid.hDiv).position());
            }
        }
        , "beforeSelectRow": function (rowid, e) {
            var cbsdis = $("tr#"+rowid+".jqgrow > td > input.cbox:disabled", "#A_Grid");
            if (cbsdis.length === 0) {
                return true;
            } else {
                return false;
            }
        }
        , "onSelectAll":function(aRowids,status){
            if (status) {
                var cbs = $("tr.jqgrow > td > input.cbox:disabled", "#A_Grid");
                cbs.removeAttr("checked");

                $("#A_Grid")[0].p.selarrrow = 
$("#A_Grid").find("tr.jqgrow:has(td > input.cbox:checked)")
                    .map(function() { return this.id; })
                    .get();

                $("#A_Grid").find("tr.jqgrow:has(td > input.cbox:disabled)")
                    .attr('aria-selected', 'false')
                    .removeClass('ui-state-highlight');
            }
        }
        , "loadComplete":function(){
             var ids = $("#A_Grid").jqGrid('getDataIDs');
            for(var i=0;i < ids.length;i++){
                if ($("#A_Grid").jqGrid('getCell', ids[i], 'company') !== '') {
                    var cb = $("tr#"+ids[i]+".jqgrow > td > input.cbox", "#A_Grid");
                    cb.attr("disabled", "disabled");
                    cb.css("display", "none");
                }
            }
        }

    , "colModel": [{
        "name": "company"
        , "index": "company"
        , "sorttype": "string"
        , "key": true
        , "label": "公司"
        , "width": 150
        , "fixed": true
        , "searchoptions": {
            "sopt": ["cn", "bw", "eq"]
        }
        , "editable": true
    }, {
        "name": "companyname"
        , "index": "companyname"
        , "sorttype": "string"
        , "key": true
        , "label": "公司名稱"
        , "width": 150
        , "fixed": true
        , "searchoptions": {
            "sopt": ["cn", "bw", "eq"]
        }
        , "editable": true
    }, {
        "name": "suppliercode"
        , "index": "suppliercode"
        , "sorttype": "string"
        , "key": true
        , "label": "供應商編號"
        , "width": 150
        , "fixed": true
        , "searchoptions": {
            "sopt": ["cn", "bw", "eq"]
        }
        , "editable": true
    }, {
        "name": "suppliername"
        , "index": "suppliername"
        , "sorttype": "string"
        , "key": true
        , "label": "供應商名稱"
        , "width": 150
        , "fixed": true
        , "searchoptions": {
            "sopt": ["cn", "bw", "eq"]
        }
        , "editable": true
    }, {
        "name": "supplieraddr"
        , "index": "supplieraddr"
        , "sorttype": "string"
        , "key": true
        , "label": "供應商地址"
        , "width": 150
        , "fixed": true
        , "searchoptions": {
            "sopt": ["cn", "bw", "eq"]
        }
        , "editable": true
    }, {
        "name": "chequedate"
        , "index": "chequedate"
        , "sorttype": "datetime"
        , "label": "cheque日期"
        , "width": 150
        , "fixed": true
        , "searchoptions": {
            "sopt": ["cn", "bw", "eq"]
        }
        , "editable": true
    }, {
        "name": "chequeaccount"
        , "index": "chequeaccount"
        , "sorttype": "string"
        , "key": true
        , "label": "cheque客戶"
        , "width": 150
        , "fixed": true
        , "searchoptions": {
            "sopt": ["cn", "bw", "eq"]
        }
        , "editable": true
    }, {
        "name": "chequeamount"
        , "index": "chequeamount"
        , "sorttype": "numeric"
        , "label": "chequeamount"
        , "width": 100
        , "fixed": true
        , "search": false
        , "align": "right"
        , "formatter": "number"
        , "formatoptions": {
            "decimalSeparator": "."
            , "thousandsSeparator": ","
            , "decimalPlaces": 2
        }
        , "editable": true
    }, {
        "name": "deliverymode"
        , "index": "deliverymode"
        , "sorttype": "string"
        , "key": true
        , "label": "deliverymode"
        , "width": 150
        , "fixed": true
        , "searchoptions": {
            "sopt": ["cn", "bw", "eq"]
        }
        , "editable": true
    }, {
        "name": "pickupcountry"
        , "index": "pickupcountry"
        , "sorttype": "string"
        , "key": true
        , "label": "pickupcountry"
        , "width": 150
        , "fixed": true
        , "searchoptions": {
            "sopt": ["cn", "bw", "eq"]
        }
        , "editable": true
    }, {
        "name": "pickupcity"
        , "index": "pickupcity"
        , "sorttype": "string"
        , "key": true
        , "label": "pickupcity"
        , "width": 150
        , "fixed": true
        , "searchoptions": {
            "sopt": ["cn", "bw", "eq"]
        }
        , "editable": true
    }, {
        "name": "pickupbank"
        , "index": "pickupbank"
        , "sorttype": "string"
        , "key": true
        , "label": "pickupbank"
        , "width": 150
        , "fixed": true
        , "searchoptions": {
            "sopt": ["cn", "bw", "eq"]
        }
        , "editable": true
    }, {
        "name": "pickuplocation"
        , "index": "pickuplocation"
        , "sorttype": "string"
        , "key": true
        , "label": "pickuplocation"
        , "width": 150
        , "fixed": true
        , "searchoptions": {
            "sopt": ["cn", "bw", "eq"]
        }
        , "editable": true
    }, {
        "name": "chequetype"
        , "index": "chequetype"
        , "sorttype": "string"
        , "key": true
        , "label": "chequetype"
        , "width": 150
        , "fixed": true
        , "searchoptions": {
            "sopt": ["cn", "bw", "eq"]
        }
        , "editable": true
    }, {
        "name": "autopayac"
        , "index": "autopayac"
        , "sorttype": "string"
        , "key": true
        , "label": "autopayac"
        , "width": 150
        , "fixed": true
        , "searchoptions": {
            "sopt": ["cn", "bw", "eq"]
        }
        , "editable": true
    }, {
        "name": "status"
        , "index": "status"
        , "sorttype": "string"
        , "key": true
        , "label": "status"
        , "width": 150
        , "fixed": true
        , "searchoptions": {
            "sopt": ["cn", "bw", "eq"]
        }
        , "editable": true
    }, {
        "name": "filename"
        , "index": "filename"
        , "sorttype": "string"
        , "key": true
        , "label": "檔案名稱"
        , "width": 150
        , "fixed": true
        , "searchoptions": {
            "sopt": ["cn", "bw", "eq"]
        }
        , "editable": true
    }]
    , "postData": {
        "oper": "grid"
    }
    , "prmNames": {
        "page": "page"
        , "rows": "rows"
        , "sort": "sidx"
        , "order": "sord"
        , "search": "_search"
        , "nd": "nd"
        , "id": "code"
        , "filter": "filters"
        , "searchField": "searchField"
        , "searchOper": "searchOper"
        , "searchString": "searchString"
        , "oper": "oper"
        , "query": "grid"
        , "addoper": "add"
        , "editoper": "edit"
        , "deloper": "del"
        , "excel": "excel"
        , "subgrid": "subgrid"
        , "totalrows": "totalrows"
        , "autocomplete": "autocmpl"
    }
    , "loadError": function(xhr, status, err) {
        try {
            jQuery.jgrid.info_dialog(jQuery.jgrid.errors.errcap, '<div class="ui-state-error">' + xhr.responseText + '</div>', jQuery.jgrid.edit.bClose, {
                buttonalign: 'right'
            });
        } catch (e) {
            alert(xhr.responseText);
        }
    }
    , "pager": "#A_GridPager"
});
jQuery('#A_Grid').jqGrid('navGrid', '#A_GridPager', {
    "edit": false
    , "add": false
    , "del": false
    , "search": false
    , "refresh": true
    , "view": false
    , "excel": false
    , "pdf": false
    , "csv": false
    , "columns": false
}, {
    "drag": true
    , "resize": true
    , "closeOnEscape": true
    , "dataheight": 150
    , "errorTextFormat": function(r) {
        return r.responseText;
    }
}, {
    "drag": true
    , "resize": true
    , "closeOnEscape": true
    , "dataheight": 150
    , "errorTextFormat": function(r) {
        return r.responseText;
    }
}, {
    "errorTextFormat": function(r) {
        return r.responseText;
    }
}, {
    "drag": true
    , "closeAfterSearch": true
    , "multipleSearch": true
}, {
    "drag": true
    , "resize": true
    , "closeOnEscape": true
    , "dataheight": 150
});
jQuery('#A_Grid').jqGrid('navButtonAdd', "#A_GridPager", {
    "caption": "匯出Excel"
    , "title": "匯出Excel"
    , "onClickButton": function() {
        $('#filters', '#A_Grid').val($('#A_Grid').getGridParam('postData').filters);
        if ($('#filters', '#A_Grid_searchform').val() != '') {
            $('#_search', '#A_Grid_searchform').val(true);
        } else {
            $('#_search', '#A_Grid_searchform').val(false);
        }
        $('#A_Grid_searchform').attr('action', 'A_GridData.php?oper=excel');
        $('#A_Grid_searchform').attr('method', 'post');
        $('#A_Grid_searchform').submit();
    }
});
jQuery('#A_Grid').jqGrid('setFrozenColumns');
$("#A_Grid").append("<form id='A_Grid_searchform' name='A_Grid_searchform'><table width='100%' border='1' cellpadding='0' cellspacing='0'><tr><td width='120' nowrap>查詢日期</td><td><input name='A_Grid_searchstarttime' id='A_Grid_searchstarttime' type='text' size=10 class='text ui-widget-content ui-corner-all' value='' readonly='readonly'>&nbsp至&nbsp<input name='A_Grid_searchendtime' id='A_Grid_searchendtime' type='text' size=10 class='text ui-widget-content ui-corner-all' value='' readonly='readonly'><input type='button' name='A_Grid_search' id='A_Grid_search' value='查詢'><input name='_search' id='_search' value='' type='hidden'><input name='filters' id='filters' value='' type='hidden'><input name='shopcode' id='shopcode' value='' type='hidden'></td><td width='120' nowrap>銷售單類別</td><td><select name='A_Grid_intercom' id='A_Grid_intercom' class='text ui-widget-content ui-corner-all'><option value='all'>全部</option><option value='exclude' selected>普通銷售單</option><option value='intercom'>IC銷售單</option></select></td><td width='120' nowrap>客戶編號/名稱</td><td><input name='A_Grid_client' id='A_Grid_client' type='text' class='text ui-widget-content ui-corner-all' value='' /></td></tr></table></form>");
$("#t_A_Grid").css('height', '70px');
$(function() {
    $("input[readOnly]").keydown(function(e) {
        e.preventDefault();
    });
    $.datepicker.setDefaults($.datepicker.regional["zh-HK"]);
    var currentDate = new Date;
    $("#A_Grid_searchstarttime").datepicker({
        //showOn: "button",
        //buttonImage: "/myphilips/img/date-picker-icon.png",
        //buttonImageOnly: true,
        onChangeMonthYear: function(y, m, i) {
            var d = i.selectedDay;
            $(this).datepicker('setDate', new Date(y, m - 1, d));
        }
        , regional: "zh-HK"
        , dateFormat: "yy-mm-dd"
        , changeMonth: true
        , changeYear: true
        , showAnim: "slide"
    });
    // $("#A_Grid_searchstarttime").val($.datepicker.formatDate('yy-mm-dd', new Date(currentDate.getFullYear(), currentDate.getMonth(), 1)));
    $("#A_Grid_searchstarttime").val($.datepicker.formatDate('yy-mm-dd', new Date()));
    $("#A_Grid_searchendtime").datepicker({
        //showOn: "button",
        //buttonImage: "/myphilips/img/date-picker-icon.png",
        //buttonImageOnly: true,
        onChangeMonthYear: function(y, m, i) {
            var d = i.selectedDay;
            $(this).datepicker('setDate', new Date(y, m - 1, d));
        }
        , regional: "zh-HK"
        , dateFormat: "yy-mm-dd"
        , changeMonth: true
        , changeYear: true
        , showAnim: "slide"
    });
    $("#A_Grid_searchendtime").val($.datepicker.formatDate('yy-mm-dd', new Date()));

    $("#A_Grid_intercom").multiselect({
        minWidth: "120"
        , multiple: false
        , selectedList: 1
    });


    $("#A_Grid_search").button().click(function() { //$("input[name='SalesDetailInquiryListGrid_delverdateselected']:checked").length
        $("#A_Grid").jqGrid("setGridParam", {
            postData: null
        });

        $("#A_Grid").jqGrid('setGridParam', {
            datatype: "json"
            , url: "A_GridData.php"
            , search: true
            , postData: $.extend($("#A_Grid").getGridParam("postData"), {
                "oper": "grid"
                , "A_Grid_searchstarttime": $("#A_Grid_searchstarttime", "#A_Grid_searchform").val()
                , "A_Grid_searchendtime": $("#A_Grid_searchendtime", "#A_Grid_searchform").val()
                , "A_Grid_intercom": $("#A_Grid_intercom" , "#A_Grid_searchform").val()
                , "A_Grid_client": $("#A_Grid_client" , "#A_Grid_searchform").val()
            })
        }).trigger('reloadGrid');
    });

    $('#A_Grid_searchform').on("keyup keypress", function(e) {
        var code = e.keyCode || e.which;
        if (code == 13) {
            e.preventDefault();
            return false;
        }
    });

    $("#A_Grid_searchform").keydown(function(event) {

        if (event.which == 13) {

            $("#A_Grid").jqGrid("setGridParam", {
                postData: null
            });

            $("#A_Grid").jqGrid('setGridParam', {
                datatype: "json"
                , url: "A_GridData.php"
                , search: true
                , postData: $.extend($("#A_Grid").getGridParam("postData"), {
                    "oper": "grid"
                    , "A_Grid_searchstarttime": $("#A_Grid_searchstarttime", "#A_Grid_searchform").val()
                    , "A_Grid_searchendtime": $("#A_Grid_searchendtime", "#A_Grid_searchform").val()
                    , "A_Grid_intercom": $("#A_Grid_intercom" , "#A_Grid_searchform").val()
                    , "A_Grid_client": $("#A_Grid_client" , "#A_Grid_searchform").val()
                })
            }).trigger('reloadGrid');
        }

    });
});
$(window).resize(function() {
    $('#A_Grid').jqGrid('setGridWidth', $(window).width() - 280);
    $('#A_Grid').jqGrid('setGridHeight', $(window).height() - 550);
});

});

function numberFormatter (cellvalue, options, rowObject) {
 ...
}
</script>

它显示如下错误: 未捕获的错误:语法错误,无法识别的表达式:tr#.jqgrow> td> input.cbox

0 个答案:

没有答案