仅按日期过滤 Telerik MVC 网格(忽略时间值)
我在 Telerik MVC Grid 中有一个 DateTime 类型的列。我只想使用它的日期部分来显示和过滤。因此,我使用了以下代码
@(Html.Telerik().Grid<State>()
.Name("tlkStateGrid")
.Columns(col => {
col.Bound(m => m.CreatedOn).Title("Created On").Format("{0:dd/MM/yyyy}");
网格确实以指定的格式显示日期(CreatedOn)。但是,过滤并没有按预期工作。我认为在过滤时,网格也会考虑时间值。因此,如果两个日期相同但时间值不同,则它们不被视为“相等”。 如何配置网格以在过滤时忽略时间值并仅比较日期。
注意:我在 Telerik MVC 论坛中发布了类似的问题,但尚未得到答案。
I have a column in Telerik MVC Grid which is of type DateTime. I want to only use the Date part of it for display and filtering. As a result, I used the following code
@(Html.Telerik().Grid<State>()
.Name("tlkStateGrid")
.Columns(col => {
col.Bound(m => m.CreatedOn).Title("Created On").Format("{0:dd/MM/yyyy}");
The Grid does display the Date (CreatedOn) in the format specified. However, the filtering doesn't work as expected. I think that while filtering, the time values are considered too by the Grid. So if two dates are same but having different time values, they are not considered 'equal'.
How do I configure grid to neglect the time values and compare only dates, when filtering.
Note: I have posted similar question in Telerik MVC forums but no answer as yet.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以修改 lambda 表达式以将 CreatedOn 属性显式修改为日期。您将仅获得日期时间对象的日期部分。
您的新代码现在如下所示。
如果 CreatedOn 是可为空的日期时间,您需要在获取 Date 组件之前访问其 Value 属性。见下文。
You could modify lambda expression to explicitly modify the CreatedOn property to be just a date. You'll get just the date component of the datetime object.
You new code will now be as below.
if CreatedOn is a nullable datetime you'll need to access its Value property before getting the Date component. See below.
我创建了以下代码,它改变了日期过滤器的定义方式:
可以像这样使用:
I've created the following code which changes the way a date-filter is defined:
This can be used like: