首页 > 解决方案 > 仅在 jqgrid 中错误显示日期选择器 bootstrap4

问题描述

将 jqgrid 从 jQueryUI 转换为 bootstrap4。除日期选择器外,所有内容均正确显示(见图)。![datepicker / jqGrid]:( https://drive.google.com/file/d/1nP7nGCPNprVFxmktvZJLupQI-xXcxcaN/view?usp=sharing ) 如何解决?

<!--my lib-->
<!--jquery-->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script>

<!--bootstrap4-->
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.47/css/bootstrap-datetimepicker.min.css"/>
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.47/js/bootstrap-datetimepicker.min.js"/>


<!--jqgrid with botstrap4 css-->
<script type="text/javascript" src="../jquery.jqGrid.min.js"></script>
<link rel="stylesheet" type="text/css" href="../css/ui.jqgrid-bootstrap4.css" />
//...
//my code snippet from jqGrid
mygrid.jqGrid({
  styleUI: "Bootstrap4",
  iconSet: "fontAwesome",
//  ...
  {label: 'created', name: 'created_at', index: 'created_at', width: 30, editable: false, align: 'right', formatter: 'date', formatoptions: {srcformat: 'Y-m-d H:i:s', newformat: 'd.m.Y H:i:s'}, editrules: {date: true},
    searchoptions:{
                        sopt:['eq','lt','le','gt','ge'],
                        dataInit: function (element) {
                            var self = this;
                            $(element).datepicker({
                                id: 'dp_created',
                                dateFormat: 'dd.mm.yy',
                                maxDate: new Date(2100, 1, 1),
                                showOn: 'focus',
                                onSelect: function () {
                                                setTimeout(function () {
                                                    self.triggerToolbar();
                                                }, 0);
                                            }                                
                            });
                        }                        
                    }
                }
// ...

标签: datepickerjqgrid

解决方案


我找到了解决方案。需要添加(网站上的设置https://gijgo.com/datepicker/configuration)。可以删除。

<!--<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script>-->

变体 1

<script src="https://unpkg.com/gijgo@1.9.13/js/gijgo.min.js" type="text/javascript"></script>
<link href="https://unpkg.com/gijgo@1.9.13/css/gijgo.min.css" rel="stylesheet" type="text/css"/>

或者

变体 2

<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.9.0/css/bootstrap-datepicker.min.css"/>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.9.0/js/bootstrap-datepicker.min.js?VERSION"></script>

对于变体 2

文档https://bootstrap-datepicker.readthedocs.io/en/latest/options.html

jqGrid中的列

        //one of the fields in the table field with dates and times
        {label: 'updated', name: 'updated_at', index: 'updated_at', width: 30, editable: false, align: 'right', formatter: 'date', formatoptions: {srcformat: 'Y-m-d H:i:s', newformat: 'd.m.Y H:i:s'}, editrules: {date: true},
            searchoptions:{
                sopt:['eq','lt','le','gt','ge'],
                dataInit: function (element) {
                   $(element).datepicker({
                        id: 'dp_updated',
                        autoclose: true,
                        format: 'dd.mm.yyyy',
                        todayHighlight: true,
                        todayBtn:true,
                        weekStart:1
                    });
                    var self = this; // save the reference to the grid
                    $(element).datepicker()
                                .on ('hide', function (e) {
                                    setTimeout(function () {self.triggerToolbar();}, 0);;
                                });                            
                }
            }
        },

        //...

        //this may be required, for example, if the date format in the filter is different from JavaScript
        mygrid.jqGrid('filterToolbar',{
            searchOperators : true,
            beforeSearch: function () {
                let postData = grd_sheme_crude.jqGrid('getGridParam', 'postData');
                let my_filters = $.parseJSON(postData.filters);
                let my_rules = filters.rules;
                let mydate_arr,filtered_field,filtered_op,correct_date_1,correct_date_2;
                rules.forEach(function(this_rule) {
                // recalculate rules/filters
                }
                postData.filters = JSON.stringify(filters);
            }


推荐阅读