I have a date column in my grid and an associated editor template for the date picker. I need to disable a lot of dates (every day except the last day of the month). I have created a list and set a ViewData object to that list of dates; however, the DataPicker editor template won't accept a ViewData object. How would I go about setting the disabled dates?
Grid:
@(Html.Kendo().Grid<HFITDashboard.UI.Models.SmaDataEntry.SmaPerformanceViewModel>() .Name("smaPerformanceGrid") .Columns(column => { column.Command(cmd => { cmd.Edit(); }).Width(300); column.Bound(s => s.SmaPerformanceId).Width(150).IncludeInMenu(false).Hidden(true); column.Bound(s => s.RefFund).Width(300).ClientTemplate("#=RefFund.LongName#"); column.Bound(s => s.RefSource).Width(250).ClientTemplate("#=RefSource.LongName#"); column.Bound(s => s.CalendarDate).Width(250).Format("{0:MM/dd/yyyy}"); column.Bound(s => s.SsbPerformanceType).Width(250).ClientTemplate("#=SsbPerformanceType.DisplayName#"); column.Bound(s => s.OneDay).Width(250).Format("{0:n2}"); column.Bound(s => s.Mtd).Width(250).Format("{0:n2}"); column.Bound(s => s.OneMonth).Width(250).Format("{0:n2}"); column.Bound(s => s.ThreeMonths).Width(250).Format("{0:n2}"); column.Bound(s => s.SixMonths).Width(250).Format("{0:n2}"); column.Bound(s => s.NineMonths).Width(250).Format("{0:n2}"); column.Bound(s => s.Qtd).Width(250).Format("{0:n2}"); column.Bound(s => s.FiscalYtd).Width(250).Format("{0:n2}"); column.Bound(s => s.CalendarYtd).Width(250).Format("{0:n2}"); column.Bound(s => s.OneYear).Width(250).Format("{0:n2}"); column.Bound(s => s.TwoYears).Width(250).Format("{0:n2}"); column.Bound(s => s.ThreeYears).Width(250).Format("{0:n2}"); column.Bound(s => s.FourYears).Width(250).Format("{0:n2}"); column.Bound(s => s.FiveYears).Width(250).Format("{0:n2}"); column.Bound(s => s.SixYears).Width(250).Format("{0:n2}"); column.Bound(s => s.SevenYears).Width(250).Format("{0:n2}"); column.Bound(s => s.EightYears).Width(250).Format("{0:n2}"); column.Bound(s => s.NineYears).Width(250).Format("{0:n2}"); column.Bound(s => s.TenYears).Width(250).Format("{0:n2}"); column.Bound(s => s.FifteenYears).Width(250).Format("{0:n2}"); column.Bound(s => s.TwentyYears).Width(250).Format("{0:n2}"); column.Bound(s => s.InceptionToDate).Width(250).Format("{0:n2}"); column.Bound(s => s.Nav).Width(250).Format("{0:n2}"); column.Bound(s => s.MarketOfferPrice).Width(250).Format("{0:n2}"); column.Bound(s => s.LastMaintenanceOperatorId).Width(150); }) .ToolBar(tb => tb.Create().Text("Create Performance Record")) .Editable(editable => editable.Mode(GridEditMode.InLine)) .ColumnMenu() .Filterable() .Pageable() .Sortable() .Scrollable(s => s.Enabled(true).Height(535)) .DataSource(ds => ds .Ajax() .PageSize(100) .Model(model => { model.Id(s => s.SmaPerformanceId); model.Field(x => x.LastMaintenanceOperatorId).Editable(false); model.Field(x => x.SsbPerformanceType).DefaultValue( ViewData["defaultSsbPerformanceTypes"] as HFITDashboard.UI.Models.SmaDataEntry.SsbPerformanceTypeViewModel); model.Field(x => x.RefSource).DefaultValue( ViewData["defaultRefSources"] as HFITDashboard.UI.Models.SmaDataEntry.RefSourceViewModel); model.Field(x => x.RefFund).DefaultValue( ViewData["defaultRefFunds"] as HFITDashboard.UI.Models.SmaDataEntry.RefFundViewModel); }) .Create(create => create.Action("Create", "SmaDataEntry")) .Read(read => read.Action("Read", "SmaDataEntry")) .Update(update => update.Action("Update", "SmaDataEntry")) .Events(e => e.RequestEnd("onRequestEnd").Sync("sync_handler")) ))
Editor Template:
@model DateTime? @(Html.Kendo().DatePickerFor(m => m))
Method that gets disabled dates:
private void GetNonMonthEndDates() { DateTime StartDate = new DateTime(2000, 1, 1); DateTime EndDate = new DateTime(2030, 12, 31); int DayInterval = 1; List<DateTime> dateList = new List<DateTime>(); while (StartDate.AddDays(DayInterval) <= EndDate) { StartDate = StartDate.AddDays(DayInterval); var daysInMonth = DateTime.DaysInMonth(StartDate.Year, StartDate.Month); if (!StartDate.Day.Equals(daysInMonth)) { dateList.Add(StartDate); } ViewData["disabledDates"] = dateList; } }
How do I associate the ViewData object to the DataPicker DisabledDates, or is there another way to do it?