datepicker - 仅在 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);
}
});
}
}
}
// ...
解决方案
我找到了解决方案。需要添加(网站上的设置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);
}
推荐阅读
- html-to-pdf - 电子邮件时间戳中的从左到右的 Unicode 字符
- windows - 在 Windows/UWP/C++ 中使用单击处理程序动态创建按钮
- python-3.x - 如何将python luigi终端输出保存在日志文件中,日志文件名中带有时间戳
- c# - EFCore 中的 SaveChanges 回调?
- c - C 通过引用传递结构
- javascript - '没有这样的文件或目录':从 S3 下载多个文件
- javascript - 尝试安装 next.js 时我做错了什么吗?
- sql-server - SSDT2012版SSIS包可以在SQL Server 2012上执行吗?
- pyqt5 - 在pyqtgraph的ImageView中显示一个QPixmap或QImage
- html - 如何从 html 中提供的句子中生成随机句子?