Kendo网格按可为空的属性排序 [英] Kendo grid sort by nullable property

查看:74
本文介绍了Kendo网格按可为空的属性排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用剑道网格的html帮助器来显示一些数据.网格使用的模型具有DateTime可为空的属性,我想在网格中显示按myDateTime属性降序排列的项目,其中第一个为null值.

I am using a html helper for Kendo grid to display some data. The model used by the grid has a DateTime nullable property and I want to display the items in grid sorted descending by myDateTime property, with the null values first.

我设法将它们显示为有序降序,但最后显示的是空值.有什么主意如何显示空值,然后显示降序的排序值?

I've managed to display them ordered descending, but the null values are displayed last. Any ideas how could I display the null values first and then the descending sorted values?

@(Html.Kendo().Grid<MyVm>()
          .Name("myGrid")
          .Columns(columns =>
          {
              columns.Bound(m => m.myDateProperty);
          })
          .Sortable()
          .DataSource(dataSource => dataSource
              .Ajax()
              .Sort(s => s.Add("myDateProperty").Descending())
              .Model(model => model.Id(a => a.Id))
              .ServerOperation(false)
                  .Read("myMethod", "myController"))

推荐答案

我认为您无法以其他任何方式解决此问题:

I don't think you can do it any other way that this workaround:

ViewModel:

ViewModel:

public class GridViewModel{
    public DateTime? myDateProperty { get; set; }
    public DateTime myDateProperty_filter { get {return myDateProperty.HasValue ? myDateProperty.Value : DateTime.MaxValue} ; }
}

控制器:

JsonResult myMethod([DataSourceRequest] DataSourceRequest request){
    //get your data and convert it to GridViewModel
    List<GridViewModel> models = getModel();
    return Json(models.ToDataSourceResult(request));
}

查看:

@(Html.Kendo().Grid<GridViewModel>()
      .Name("myGrid")
      .Columns(columns =>
      {
          columns.Bound(m => m.myDateProperty_filter).ClientTemplate("#= myDateProperty #");
      })
      .Sortable()
      .DataSource(dataSource => dataSource
          .Ajax()
          .Sort(s => s.Add("myDateProperty_filter").Descending())
          .Model(model => model.Id(a => a.Id))
          .ServerOperation(false)
              .Read("myMethod", "myController"))

这篇关于Kendo网格按可为空的属性排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆