Kendo Grid MVC绑定字符串列到目前为止

时间:2017-10-25 14:55:24

标签: c# asp.net-mvc kendo-ui kendo-grid

我有一个kendo网格,它接收来自json字符串的日期作为字符串。我尝试在控制器中将日期转换为日期时间,但我仍然没有从网格中获取日期过滤器。

@(Html.Kendo().Grid<PTORequestsVM>()
     .Name("grid")
     .ToolBar(tools => tools.Excel())
     .Excel(e => e.AllPages(true))
     .Excel(excel => excel
     .FileName("HR.xlsx")
                  )
                  .Columns(columns =>
                  {
                      columns.Bound(e => e.EmployeeID).Hidden(true).IncludeInMenu(true);
                      columns.Bound(e => e.EmployeeName).Width(223);
                      columns.Bound(e => e.Department);
                      columns.Bound(e => e.dispType).Title("PTO Type");
                      columns.Bound(e => e.dispSDate).Width(120).Title("Start Date").Format("{0:dd/MM/yyyy}").Sortable(true);
                      //columns.Bound(e => e.StartDate).Width(120).Format("{0:MM/dd/yyyy}");
                      columns.Bound(e => e.dispEDate).Width(120).Title("End Date").Format("{0:dd/MM/yyyy}").Sortable(true);
                      //columns.Bound(e => e.EndDate).Width(120).Format("{0:MM/dd/yyyy}");
                      columns.Bound(e => e.StartTime);
                      columns.Bound(e => e.EndTime);
                      columns.Bound(e => e.TotalRequestedTime).Title("Total Time");
                      columns.Bound(e => e.dispStatus).Width(100).Title("Status");
                      columns.Template(@<text>

                    </text>)
                          .ClientTemplate(
                              "<div class='icon-center'>" +
                          //"<a href='" + Url.Action("EditPTO", "HR", new { id = "#=Id#" }) + "' title='Edit'><i class='icon-edit fa fa-pencil fa-fw fa-lg'></i></a>" +
                          //"<a href='" + Url.Action("ApprovePTO", "HR", new { id = "#=Id#" }) + "' title='Edit'><i class='icon-green fa fa-check fa-fw fa-lg'></i></a>" +
                              "<span class='talk-to-the-hand' title='Delete' id='delete' data-id='#=Id#' style='display: #=AllowDelete#;'><i class='icon-red fa fa-times fa-fw fa-lg'></i></span>" +
                              "</div>").Width(80).Title("Actions");
                  })
  .Sortable()
  .Scrollable()
  .Groupable()
  .ColumnMenu()
  .Pageable()
  .Filterable()
  .ClientDetailTemplateId("template")
  .HtmlAttributes(new { style = "height:764px;" })
  .Reorderable(reorder => reorder.Columns(true))
  .Resizable(resize => resize.Columns(true))
  .DataSource(dataSource => dataSource
      .Ajax()
      .Read(read => read.Action("PTORequestHist_Read", "HR"))
  )
  .Events(events => events.DataBound("dataBound"))
            )

我需要指定StartDate和EndDate列是日期而不是字符串但不确定如何操作。

2 个答案:

答案 0 :(得分:1)

您可以使用ClientTemplate

$config['enable_hooks'] = TRUE;

答案 1 :(得分:0)

我能够使用

从字符串转换控制器中的日期
EndDate = new DateTime(req.EndDate.Year, req.EndDate.Month, req.EndDate.Day, 12, req.EndDate.Minute, req.EndDate.Second, DateTimeKind.Utc),