我无法在chequedate列中显示日期选择器

时间:2019-07-19 09:33:15

标签: javascript jqgrid

我在chequeamount列中添加了datepicker,如果显示结果,我想在chequedate列中显示datepicker,人们可以选择datepicker中的日期进行修改和保存(保存功能不显示如下代码),但是当我在chequedate的列模型中添加datepicker代码时,它不起作用

            require_once './php/jq-config.php';
            // include the jqGrid Class
            require_once "./php/PHPSuito/jqGrid.php";
            // include the driver class
            require_once "./php/PHPSuito/DBDrivers/jqGridPdo.php";

            // create the array connection
            $conn_A_Grid = new PDO(DB_DSN,DB_USER,DB_PASSWORD); 
            ?>
            <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

                    , "gridview": true
                    , "width": $(window).width() - 280
                    //, "rownumbers": true
                    , "rownumWidth": 35
                    , "datatype": "json"
                    , "url": "A_GridData.php"
                    , "editurl": "A_GridData.php"
                    , "cellurl": "A_GridData.php"
                    , "caption": "產生HSBC"
                    , "rowNum": 1000
                    , "multiSort": false
                    // , "sortname": "invcode"
                    , "loadui": "block"
                    , "altRows": true
                    , "altclass": "custAltRowClass"
                    , "autowidth": false
                    , "mtype": "POST"
                    , "multiselect": true
                    , "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": "seqno"
                        , "index": "seqno"
                        , "sorttype": "number"
                        , "key": true
                        , "width": 150
                        , "fixed": true
                        , "searchoptions": {
                            "sopt": ["cn", "bw", "eq"]
                        }
                        , "editable": true
                        , "hidden": true
                    }, {
                        "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
                        , "formatter": "date"
                        , "searchoptions": {
                            "sopt": ["cn", "bw", "eq"]
                        }
                        ,"formatoptions": {
                            "reformatAfterEdit": true
                            ,"srcformat": "Y-m-d H:i:s"
                            ,"newformat": "Y-m-d"
                        }
                        , "editable": true
                        , "edittype": 'text' 
                        , "editoptions": { 
                              size: 12, 
                              maxlengh: 12, 
                              dataInit: function (element) { 
                                  $(element).datepicker({ dateFormat: 'mm/dd/yy' })
                              }
                        }
                        , "editrules": {date: 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": "second_party_ac"
                        , "index": "second_party_ac"
                        , "sorttype": "string"
                        //, "key": true
                        , "label": "second_party_ac"
                        , "width": 150
                        , "fixed": true
                        , "searchoptions": {
                            "sopt": ["cn", "bw", "eq"]
                        }
                        , "editable": true
                    }, {
                        "name": "bia"
                        , "index": "bia"
                        , "sorttype": "string"
                        //, "key": true
                        , "label": "BIA account"
                        , "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": "匯出print cheque"
                    , "title": "匯出print cheque"
                    , "onClickButton": function() {
                        genPrintCheque();
                    }
                });
                jQuery('#A_Grid').jqGrid('setFrozenColumns');
                $("#t_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_searchtime' id='A_Grid_searchtime' type='text' size=10 class='text ui-widget-content ui-corner-all' value='' readonly='readonly'><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_status' id='A_Grid_status' class='text ui-widget-content ui-corner-all'><option value='all'>全部</option><option value='new' selected>New</option><option value='generated'>Generated</option></select></td><td width='120' nowrap>種類</td><td><select name='A_Grid_chequetype' id='A_Grid_chequetype' class='text ui-widget-content ui-corner-all'><option value='autopay' selected>AutoPay</option><option value='outsourcing'>Outsourcing</option></select></td><td width='120' nowrap>檔案名稱</td><td><input name='A_Grid_filename' id='A_Grid_filename' type='text' class='text ui-widget-content ui-corner-all' value='' />&nbsp&nbsp<input type='button' name='A_Grid_search' id='A_Grid_search' 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_searchtime").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_searchtime").val($.datepicker.formatDate('yy-mm-dd', new Date()));

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

                    $("#A_Grid_chequetype").multiselect({
                        minWidth: "150"
                        , 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_searchtime": $("#A_Grid_searchtime", "#A_Grid_searchform").val()
                                , "A_Grid_status": $("#A_Grid_status" , "#A_Grid_searchform").val()
                                , "A_Grid_filename": $("#A_Grid_filename" , "#A_Grid_searchform").val()
                                , "A_Grid_chequetype": $("#A_Grid_chequetype" , "#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_searchtime": $("#A_Grid_searchtime", "#A_Grid_searchform").val()
                                    , "A_Grid_status": $("#A_Grid_status" , "#A_Grid_searchform").val()
                                    , "A_Grid_filename": $("#A_Grid_filename" , "#A_Grid_searchform").val()
                                    , "A_Grid_chequetype": $("#A_Grid_chequetype" , "#A_Grid_searchform").val()
                                })
                            }).trigger('reloadGrid');
                        }

                    });
                });

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

            });


                //The gen Print Cheque button that generate the Ifile for HSBC
                function genPrintCheque(){
                    var myGrid = jQuery('#A_Grid');
                    var selRowId = myGrid.jqGrid ('getGridParam','selarrrow');
                    if (selRowId.length>0) {
                        var enSelrowID = encodeURI(selRowId);
                        $.ajax({
                            url: "A_echeque.php",
                            type: "POST",
                            async: false,
                            data: {seqno: enSelrowID, chequetype: $("#A_Grid_chequetype", "#A_Grid_searchform").val()},
                            success: function(response){
                                response = JSON.parse(response);
                                if(response['message'] == 'success'){
                                    showAlertDialog('success');
                                    jQuery("#A_Grid").trigger("reloadGrid");
                                }
                            }
                        });

                    }else{
                        showAlertDialog('請先選擇項目!');
                    }
                }

            function numberFormatter (cellvalue, options, rowObject) {
                if (isNaN(cellvalue)) {
                    return cellvalue;
                } else {
                    return parseFloat(cellvalue).toFixed(2).replace(/(\d)(?=(\d{3})+\.)/g, '$1,');
                }
            }
            </script>

当我点击chequedate列时,它不显示日期选择器,我也不知道为什么

0 个答案:

没有答案