I am using the client side controls. I am unable to get the time portion of a datetime field in SQL to show up correctly in the grid. Code is listed below.
<section id="dateSection">
<input id="datepicker" onchange="fetchAvailability" />
</section>
<section id="gridSection">
</section>
<script type="text/javascript">
function fetchAvailability(value) {
//get Date and Fetch Availability...
//var date = $('datepicker').val();
debugger;
//alert(value);
var dateToFetch = kendo.toString(value, 'd');
dateToFetch = dateToFetch.replace('/', '-');
dateToFetch = dateToFetch.replace('/', '-');
var url = "/Availability/GetByDate/" + dateToFetch;
//alert(url);
$("#gridSection").kendoGrid({
dataSource: {
type: "json",
transport: {
read: url
},
pageSize: 100
},
sortable: true,
pageable: {
refresh: true,
pageSizes: true,
buttonCount: 5
},
columns: [{
field: "FirstName",
title: "FirstName",
width: 140
}, {
field: "LastName",
title: "LastName",
width: 190
}, {
field: "StartDateTime",
title: "Start",
format: "{0:yyyy-MM-dd HH:mm}",
//template: '#= kendo.toString(new Date(parseInt(StartDateTime.replace(/[A-Za-z$--/]/g, ""))),"MM-dd-yyyy mm:ss tt") #',
width: 200
}, {
field: "EndDateTime",
title: "End",
template: '#= kendo.toString(new Date(parseInt(EndDateTime.replace(/[A-Za-z$--/]/g, ""))),"MM-dd-yyyy mm:ss tt") #',
width: 200
}, {
field: "Subject",
title: "Comments"
}]
});
}
$(document).ready(function () {
// create DateTimePicker from input HTML element
$("#datepicker").kendoDatePicker({
change: function () {
var value = this.value();
fetchAvailability(value);
//console.log(value); //value is the selected date in the datepicker
},
value: new Date()
});
});
</script>
/////CONTROLLER CODE>>>
public ActionResult GetByDate(string id)
{
DateTime fetchDate = DateTime.Now;
if (!string.IsNullOrEmpty(id))
{
fetchDate = DateTime.Parse(id.Replace("-", "/"));
}
//DateTime fetchDate = DateTime.Parse(id);
return Json(getAvailability(fetchDate), JsonRequestBehavior.AllowGet);
}
private IEnumerable<ViewModel.Availability> getAvailability(DateTime date)
{
var dc = new baddDBData();
DateTime startDate = date.Date;
DateTime endDate = startDate.AddDays(1).AddTicks(-1);
//var baddDB = from m in dc.Availabilities.Where(m => m.StartDateTime.Equals(date.Date))
var baddDB = from m in dc.vwAvailableUsers.Where(e => e.StartDateTime >= startDate && e.StartDateTime <= endDate)
select new ViewModel.Availability
{
Id = m.Id,
StartDateTime = m.StartDateTime,
//StartTime = m.StartDateTime.ToShortTimeString(),
EndDateTime = m.EndDateTime,
//EndTime = m.EndDateTime.ToShortTimeString(),
FirstName = m.FirstName,
LastName = m.LastName,
Subject = m.Subject
//Devotion = m.Devotion,
//Subject = "Badd Meeting"
};
return baddDB;
}
//////MODEL>>>>
class Availability
{
public int Id { get; set; }
public int MemberId { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public DateTime StartDateTime { get; set; }
public string StartTime { get; set; }
public string EndTime { get; set; }
public DateTime EndDateTime { get; set; }
public string Subject { get; set; }
}
<section id="dateSection">
<input id="datepicker" onchange="fetchAvailability" />
</section>
<section id="gridSection">
</section>
<script type="text/javascript">
function fetchAvailability(value) {
//get Date and Fetch Availability...
//var date = $('datepicker').val();
debugger;
//alert(value);
var dateToFetch = kendo.toString(value, 'd');
dateToFetch = dateToFetch.replace('/', '-');
dateToFetch = dateToFetch.replace('/', '-');
var url = "/Availability/GetByDate/" + dateToFetch;
//alert(url);
$("#gridSection").kendoGrid({
dataSource: {
type: "json",
transport: {
read: url
},
pageSize: 100
},
sortable: true,
pageable: {
refresh: true,
pageSizes: true,
buttonCount: 5
},
columns: [{
field: "FirstName",
title: "FirstName",
width: 140
}, {
field: "LastName",
title: "LastName",
width: 190
}, {
field: "StartDateTime",
title: "Start",
format: "{0:yyyy-MM-dd HH:mm}",
//template: '#= kendo.toString(new Date(parseInt(StartDateTime.replace(/[A-Za-z$--/]/g, ""))),"MM-dd-yyyy mm:ss tt") #',
width: 200
}, {
field: "EndDateTime",
title: "End",
template: '#= kendo.toString(new Date(parseInt(EndDateTime.replace(/[A-Za-z$--/]/g, ""))),"MM-dd-yyyy mm:ss tt") #',
width: 200
}, {
field: "Subject",
title: "Comments"
}]
});
}
$(document).ready(function () {
// create DateTimePicker from input HTML element
$("#datepicker").kendoDatePicker({
change: function () {
var value = this.value();
fetchAvailability(value);
//console.log(value); //value is the selected date in the datepicker
},
value: new Date()
});
});
</script>
/////CONTROLLER CODE>>>
public ActionResult GetByDate(string id)
{
DateTime fetchDate = DateTime.Now;
if (!string.IsNullOrEmpty(id))
{
fetchDate = DateTime.Parse(id.Replace("-", "/"));
}
//DateTime fetchDate = DateTime.Parse(id);
return Json(getAvailability(fetchDate), JsonRequestBehavior.AllowGet);
}
private IEnumerable<ViewModel.Availability> getAvailability(DateTime date)
{
var dc = new baddDBData();
DateTime startDate = date.Date;
DateTime endDate = startDate.AddDays(1).AddTicks(-1);
//var baddDB = from m in dc.Availabilities.Where(m => m.StartDateTime.Equals(date.Date))
var baddDB = from m in dc.vwAvailableUsers.Where(e => e.StartDateTime >= startDate && e.StartDateTime <= endDate)
select new ViewModel.Availability
{
Id = m.Id,
StartDateTime = m.StartDateTime,
//StartTime = m.StartDateTime.ToShortTimeString(),
EndDateTime = m.EndDateTime,
//EndTime = m.EndDateTime.ToShortTimeString(),
FirstName = m.FirstName,
LastName = m.LastName,
Subject = m.Subject
//Devotion = m.Devotion,
//Subject = "Badd Meeting"
};
return baddDB;
}
//////MODEL>>>>
class Availability
{
public int Id { get; set; }
public int MemberId { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public DateTime StartDateTime { get; set; }
public string StartTime { get; set; }
public string EndTime { get; set; }
public DateTime EndDateTime { get; set; }
public string Subject { get; set; }
}