剑道网格中的日期时间过滤器 [英] Datetime filter in kendo grid
问题描述
我的代码在C#.NET中 我正在使用Kendo Grid 2013.2.716.340版和服务器绑定来在网格中显示数据.
My code is in C# .NET I am using Kendo Grid version 2013.2.716.340 and server binding to show data in grid.
在Kendo UI Grid中,我有一个dateTime
列,但列过滤器输入仅具有日期选择器,而没有时间选择器.因此,如果我选择选项IsEqualTo
并给出一个日期,则在过滤器中将时间设置为00:00:00
时,我将得到零结果,但这些列具有一些时间值.
我想将时间选择器和日期选择器一起添加.
In Kendo UI Grid, I have a dateTime
column but the column filter input only has a date picker but no time picker. Due to this if I select the option IsEqualTo
and give a date then I get zero results as the time is set to 00:00:00
in the filter but the columns have some time value.
I want to add time picker along with date picker.
我试图在我的专栏上做到这一点,但是没有用:
I tried to do this on my column, but it didn't work:
columns.Bound(o => o.Time).Title("Time").Format("{0:MM/dd/yyyy HH:mm:ss}").Filterable(f => f.UI("DateTimeFilter")).Width("5%");
并已应用以下脚本:
<script type="text/javascript">
function DateTimeFilter(control)
{
$(control).kendoDateTimePicker();
}
</script>
当我从datetimepicker
中选择精确的datetime
时,上面的代码有效,但是当我选择isequalto
时,则无效.
例如:如果我在剑道网格列中显示此datetime
"12/21/2013 07:15:45",并且在过滤器下将此datetime
复制到isequalto
选项时,它不提供任何数据.
The above code works when I select exact datetime
from datetimepicker
but it doesn't work when I select isequalto
.
For eg : If I have this datetime
"12/21/2013 07:15:45" displayed in my kendo grid column and when I copy this datetime
to isequalto
option under filter it does not gives any data.
我还尝试了链接上提供的示例在我的情况下也没有用.此链接上的示例使用Ajax绑定.在服务器绑定的情况下,我需要应用它.
Also I tried the example provided on this link It also didn't work in my case. Example on this link uses Ajax binding. I need to apply it in case of server binding.
这是显示我要应用的附件的图像. >是图像的链接.
如果我将网格中显示的datetime
复制到过滤器中,则应该正确过滤并给出结果.
This is an attached image that shows what I want to apply. Here is the link for image.
If I copy the datetime
shown in grid to the filter It should filter correctly and give result.
如果有人可以帮助我解决我的问题,我将非常感谢.预先感谢.
I will be very thankful if anybody could help me out in solving my issue. Thanks in advance.
推荐答案
根据我的经验,kendoDateTimePicker确实很挑剔.如果过滤器的格式无法指定列数据的日期时间精度,则将找不到它.
From my experience, the kendoDateTimePicker is really picky; if the format of the filter cannot specify the datetime precision of the column data, it will not find it.
在您的情况下,列格式为"MM/dd/yyyy HH:mm:ss"
(以秒为单位). kendoDateTimePicker的默认格式为"MM/dd/yyyy h:mm tt"
(没有秒和小时的规范不匹配).由于您初始化了默认的kendoDateTimePicker,因此无论您将其放置在选择器中是什么,您都无法将其过滤为IS EQUAL TO
列值的日期,因为您无法输入多少秒.
In your case, your column format is "MM/dd/yyyy HH:mm:ss"
(with seconds). The default format for the kendoDateTimePicker is "MM/dd/yyyy h:mm tt"
(without seconds and hour spec is mismatched). Since you initialized a default kendoDateTimePicker, no matter what you put in the picker, you could never filter to a date that IS EQUAL TO
a column value since you couldn't input how many seconds it was.
确保其正常工作的最简单方法是对column和kendoDateTimePicker使用相同的格式.将此替换为DateTimeFilter
函数:
The easiest way to ensure it works is to use the same format for both column and the kendoDateTimePicker . Replace your DateTimeFilter
function with this:
function DateTimeFilter(control)
{
$(control).kendoDateTimePicker({
format: "MM/dd/yyyy HH:mm:ss",
timeFormat: "HH:mm:ss"
});
}
关于kendoDateTimePicker:
With regards to the kendoDateTimePicker:
-
format
定义控件的输入值格式 -
timeFormat
定义时间选择器的时间格式 -
interval
(上面没有使用它),但是它指定了时间选择器的每个选项之间的时间间隔(以分钟为单位).
format
defines the input value format for controltimeFormat
defines the time format of the time pickerinterval
(didn't use it above), but it specifies the time interval in minutes between each option of the time picker.
我没有使用asp.net mvc,所以我不确定100%是否可以解决您的问题.但是,我敢肯定,它至少可以解决您遇到的一些过滤问题.如果需要,我可以为纯html/javascript示例提供jsfiddle.
I am not using asp.net mvc, so I'm not 100% sure if this solves your problem. However I am certain it will clear up at least some of the filtering issues you have. I can provide a jsfiddle for a purely html/javascript sample if you want.
这篇关于剑道网格中的日期时间过滤器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!