C# 使用YYYY-MM日期格式的剑道网格过滤器

C# 使用YYYY-MM日期格式的剑道网格过滤器,c#,asp.net-mvc,kendo-ui,kendo-grid,kendo-asp.net-mvc,C#,Asp.net Mvc,Kendo Ui,Kendo Grid,Kendo Asp.net Mvc,我的问题描述如下: 我想用“YYYY-MM”格式按月份(BudgetItemStartDate字段)过滤剑道网格结果。当我选择所需月份的第一天时,过滤器工作正常!(当深度和开始设置为“月”时,但这不是我想要的情况)。我需要的是筛选出的结果只是选择一个月。当选择一个月时,我仍然得到空结果 @(Html.Kendo().Grid<ServiceCostReportDTO>() .Name("ServiceCostReportListGrid") .Columns(c

我的问题描述如下: 我想用“YYYY-MM”格式按月份(BudgetItemStartDate字段)过滤剑道网格结果。当我选择所需月份的第一天时,过滤器工作正常!(当深度和开始设置为“月”时,但这不是我想要的情况)。我需要的是筛选出的结果只是选择一个月。当选择一个月时,我仍然得到空结果

 @(Html.Kendo().Grid<ServiceCostReportDTO>()
     .Name("ServiceCostReportListGrid")
     .Columns(cols =>
     {
      ...
      cols.Bound(m => m.BudgetItemStartDate)
          .Title("Budget Item Start Date")
          .Format("{0:yyyy-MM}")
          .Width(130)
          .HeaderHtmlAttributes(new { style = "background-color: Beige;" })
          .Filterable(f => f.Cell(c => c.Template("dateFilter")));
      ...
     }
    .DataSource(dataSource => dataSource
    .Ajax()
    .ServerOperation(true)
    .PageSize(AppSession.Current.GetParameterValue<int>(AppConstants.ConfigParameters_PageSize))
    .Read(read => read.Action("ReadServiceCostReportList", "ServiceCostReport").Data("getFilterValues"))
    )
    .Resizable(resize => resize.Columns(true))
    .AutoBind(true) //This will not automatically call the read action
    .Excel(excel => excel
        .FileName("Service_Cost_Report_" + DateTime.Now.Year + "_" + DateTime.Now.Month + "_" + DateTime.Now.Day + "_" + DateTime.Now.Hour + "_" + DateTime.Now.Minute + "_" + DateTime.Now.Second + ".xlsx")
        .AllPages(true)
        .Filterable(true)
        .ProxyURL(Url.Action("Excel_Export_Save", "ExcelExport"))
    )
    .ToolBar(t =>
    {
        //t.Template("<a class='k-button' onclick='excelExport()' href='#'><span class='k-icon k-i-excel'></span>Export to Excel</a>");
        t.Excel();
    })
    .ColumnMenu(x => {
        x.Sortable(true);
        x.Filterable(true);
    })
    .Events(e => {
        e.DataBound("resizeGrid");
    })
    .Sortable()
    .Reorderable(reorder => reorder.Columns(true))
    .Pageable()
    .Editable(editing => editing.Enabled(false))
    .Scrollable(cfg => cfg.Height("auto"))
    //.Groupable()
    .Filterable(ftb =>
    {
        ftb.Mode(GridFilterMode.Row);
        ftb.Messages(m => m.IsFalse("No"));
        ftb.Messages(m => m.IsTrue("Yes"));
    })
在我的例子中,YYYY-MM格式的日期作为字符串存储在数据库中。因此,当我从数据库中检索数据时,我的模型如下所示

public class ServiceCostReportDTO
{
  ...
  public string BudgetSplitStartDateString {get; set;}
  public DateTime? BudgetSplitStartDate
  {
        get
        {
            if (BudgetSplitStartDateString != null)
                return new DateTime(int.Parse(BudgetSplitStartDateString.Substring(0, 4)), int.Parse(BudgetSplitStartDateString.Substring(5, 2)), 1);
            else
                return null;
            //return TimeZoneInfo.ConvertTimeToUtc(new DateTime(int.Parse(StartDateString.Substring(0, 4)), int.Parse(StartDateString.Substring(5, 2)), 1));
        }
        set 
        {
            if (BudgetSplitStartDate != null)
            {
                BudgetSplitStartDateString = value.GetValueOrDefault().Year.ToString() + "-" + value.GetValueOrDefault().Month.ToString("0#");
            }
            else
            {
                BudgetSplitStartDateString = null;
            }
        }
    }
   ...
  }
我尝试了很多解决方法,但没有找到解决这个问题的方法。有人能帮我吗?谢谢


那么你想从表格中选择一个开始日期,并将相关信息返回到同一个表格中吗?你能提供一个例子,是截图还是某个地方的演示表吗?@noobed,我在这篇文章中附上了4个截图。谢谢。@David从截图中我看到的是日期正在以不同的格式进行解析(过滤)。这可能是造成问题的原因。
public class ServiceCostReportDTO
{
  ...
  public string BudgetSplitStartDateString {get; set;}
  public DateTime? BudgetSplitStartDate
  {
        get
        {
            if (BudgetSplitStartDateString != null)
                return new DateTime(int.Parse(BudgetSplitStartDateString.Substring(0, 4)), int.Parse(BudgetSplitStartDateString.Substring(5, 2)), 1);
            else
                return null;
            //return TimeZoneInfo.ConvertTimeToUtc(new DateTime(int.Parse(StartDateString.Substring(0, 4)), int.Parse(StartDateString.Substring(5, 2)), 1));
        }
        set 
        {
            if (BudgetSplitStartDate != null)
            {
                BudgetSplitStartDateString = value.GetValueOrDefault().Year.ToString() + "-" + value.GetValueOrDefault().Month.ToString("0#");
            }
            else
            {
                BudgetSplitStartDateString = null;
            }
        }
    }
   ...
  }