JqGrid,工具栏搜索栏添加清除按钮
我有一个启用工具栏搜索的 JqGrid。我的专栏之一是日期时间列,搜索字段是 jquery 日期选择器。日期选择器的问题是不能有空值,但由于该字段是过滤器,因此可以为空。所以我想做的是在日期选择器附近添加一个小按钮,这将清除该字段。 有没有办法做到这一点,或者能够从客户端清除日期选择器。
这是该专栏的代码
{ name: 'Period', index: 'Period', align: 'center', formatter: 'date', formatoptions: { newformat: 'F, Y' }, width: '70px', search: true,
searchoptions: {
dataInit: function (el) {
$(el).datepicker({
yearRange: "-5:+1",
changeMonth: true,
changeYear: true,
showButtonPanel: true,
dateFormat: 'MM, yy',
onClose: function (dateText, inst) {
var month = $("#ui-datepicker-div .ui-datepicker-month :selected").val();
var year = $("#ui-datepicker-div .ui-datepicker-year :selected").val();
$(this).datepicker('disable');
$(this).datepicker('setDate', new Date(year, month, 1));
$(this).datepicker('enable');
$("#jqgCompLine")[0].triggerToolbar();
},
beforeShow: function (input, inst) {
if ((datestr = $(this).val()).length > 0) {
year = datestr.substring(datestr.length - 4, datestr.length);
month = jQuery.inArray(datestr.substring(0, datestr.length - 6), $(this).datepicker('option', 'monthNames'));
$(this).datepicker('option', 'defaultDate', new Date(year, month, 1));
$(this).datepicker('setDate', new Date(year, month, 1));
}
}
});
}
},
提前感谢您的帮助!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
datepicker
对于空字段没有问题。估计是你的定制的问题。我不知道您有哪些数据作为网格中的日期值。格式
'F, Y'
(以及日期选择器的'MM, yy'
)似乎有点奇怪,因为搜索将按完整日期完成,但您显示只有口和年。也许一切都可以正确地处理您的数据,也可能不会。我创建了演示来演示使用日期选择器进行搜索。在创建演示期间,我使用了 'j, F, Y' 格式(对于日期选择器 'd, MM, yy' 格式),并发现了两个错误<一href="https://github.com/tonytomov/jqGrid/blob/v4.3.1/js/grid.base.js#L84-130" rel="nofollow">parseDate jqGrid内部使用的方法。
第一个问题在行 其中
date[k]
值将被正确计算,但不会分配给tsp.m
。应在两个if
语句中插入赋值tsp.m = date[k];
。所以'F'和'M'格式在jqGrid的当前代码中工作不正确。因为您使用“F”格式,所以它对您来说可能很重要。下一个问题是当天的
'j'
格式将以错误的方式处理。在解析日期期间,tsp.j
将被正确分配,但tsp.d
将在 该行将不会被修改并保持等于1。修复代码我建议添加 行for 循环之后某处的 。 演示使用修改后的版本jquery.jqGrid.src.js 的 rel="nofollow">jquery.jqGrid.src-parseDate.js。
我稍后会向 trirand 报告该错误和我的修复。
The
datepicker
have no problem with empty fields. I suppose it's the problem with your customization.I don't know which data you have as the date values in the grid. The format
'F, Y'
(and'MM, yy'
for the datepicker) seems me a little strange because the searching will be done by full date, but you display only the mouth and year. Probably all will work correct with your data probably not.I created the demo to demonstrate that searching with the datepicker. During creating of the demo I used the 'j, F, Y' format (for the datepicker the 'd, MM, yy' format) and found two bugs in the parseDate method used by jqGrid internally.
The first problem are in the lines where
date[k]
value will be correct calculated, but not assigned totsp.m
. One should insert in bothif
statements the assignmenttsp.m = date[k];
. So both 'F' and 'M' formats works incorrect in the current code of jqGrid. Because you use 'F' format it could be important for you.The next problem is that the
'j'
format for the day will be processed in the wrong way. During the parsing of the date thetsp.j
will be correctly assigned, but thetsp.d
, which will be used in the line, will be not modified and stay equal to 1. To fix the code I suggest to add the linesomewhere after the for loop. The demo used the modified version jquery.jqGrid.src-parseDate.js of the
jquery.jqGrid.src.js
of jqGrid 4.3.1.I will report the bug and my fix to trirand later.