我在这里的问题描述如下: 我想以“ 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"));
})
Kendo日期时间选择器模板
function dateFilter(e) {
e.element.kendoDatePicker({
depth: "year",
start: "year",
format: "yyyy-MM",
parseFormat: "yyyy-MM",
})
}
在我的情况下,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;
}
}
}
...
}
我尝试了许多变通办法,但未能设法解决此问题。有谁可以帮助我吗?谢谢!