Kendo grid MVC 列的嵌套属性的可过滤选项

huangapple go评论64阅读模式
英文:

Kendo grid mvc filterable option for column nested property

问题

我正在使用asp.net core MVC kendo grid列,其中包含一个嵌套属性。我有一个名为"CreatedDate"的列,其类型为datetime,但我只想使用属性中的日期部分,类似于"CreatedDate.Date"。我已经为"CreatedDate"列应用了filterable选项,并且它正常工作。

columns.Bound(c => c.CreatedDate).Title("Created On")
        .Filterable(x => x.Operators(d => d.ForDate(o => o.Clear()
                      .IsGreaterThan("Is Greater Than") 
                        .IsLessThan("Is Less Than"))));

但是,当我为同一列的嵌套属性"CreatedDate.Date"应用filterable选项时,它不起作用。所有的过滤选项都显示在列表中。

columns.Bound(c => c.CreatedDateTimeUtc.Date).Title("Created On")
                           .Filterable(x => x.Operators(d => d.ForDate(o => o.Clear()
                           .IsGreaterThan("Is Greater Than")
                              .IsLessThan("Is Less Than"))));

我是否漏掉了任何内容以应用自定义filterable选项到嵌套属性?请帮我解决这个问题。

英文:

I am using asp.net core MVC kendo grid column with a nested property.I have column "CreatedDate" of type datetime but i want to use only date part from the property like "CreatedDate.Date". I have applied filterable option for column "CreatedDate" and it is working fine.

   columns.Bound(c => c.CreatedDate).Title("Created On")
    .Filterable(x=>x.Operators(d=>d.ForDate(o=>o.Clear()
                  .IsGreaterThan("Is Greater Than") 
                    .IsLessThan("Is Less Than"))));

But when i apply filterable option for the same column with nested property like "CreatedDate.Date" it is not working. All the filter option are showed in the list.

 columns.Bound(c => c.CreatedDateTimeUtc.Date).Title("Created On")
                       .Filterable(x=>x.Operators(d=>d.ForDate(o=>o.Clear()
                       .IsGreaterThan("Is Greater Than")
                          .IsLessThan("Is Less Than"))));

Am i missing anything to add for nested property to apply custom filterable option? Please help me out from this issue

答案1

得分: 0

我认为Kendo默认不会过滤复杂对象。一种选择是将该字段添加到您的视图模型中,这样它就不再是复杂对象。否则,您可以捕获过滤事件,并在JavaScript函数中处理该字段的过滤。

这份文档可能会有帮助:

https://demos.telerik.com/aspnet-mvc/grid/events

https://docs.telerik.com/kendo-ui/knowledge-base/grid-filter-column-with-dropdownlist

英文:

I think Kendo doesn't filter complex objects out of the box. One option is to add the field to your view model so it's not complex anymore. Otherwise you can capture the filter event and take care of the filtering for that field in a javascript function.

This documentation might be helpful:

https://demos.telerik.com/aspnet-mvc/grid/events

https://docs.telerik.com/kendo-ui/knowledge-base/grid-filter-column-with-dropdownlist

huangapple
  • 本文由 发表于 2020年1月6日 21:31:38
  • 转载请务必保留本文链接:https://go.coder-hub.com/59613034.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定