I have a grid that is displaying a date of 1/1/2013 (It was populated from a DateTime object 1/1/2013 5:00 AM in UTC time)
It displays in the grid as 1/1/2013. However when I do the following to get the underlying record for the row and log the columns value to the console it is now incorrect and displays in the console Mon Dec 31 2012 19:00:00 GMT-0500 (Eastern Standard Time)
I use the following calls to get at the record that was used to populate the grid
var grid = patientInfo.data("igGrid");
var records = grid.dataSource.dataView();
var activeRecord = records[index];
What can I do to keep the correct date/time in the grid. I have tried converting all DateTime objects ToUniversalTime and that did not help
Hello Donald,
Please let me know if you need any further assistance regarding this matter.
Unfortunately that did not solve my problem..
Unfortunately your example is html, and my code uses MVC.
Here is my console output in Chrome. You will see below that the dates that were added for Fred and Jane were 1/1/2013 12:00 AM, It displays 1/1/2013 in the grid but when retrieved it is incorrect.
I have added some MVC code that demonstrates the problem
Here is the Data model I am using
using System; using System.Runtime.Serialization;
namespace DateTestMVC.Models { [DataContract] public class DataModel { [DataMember] public string PatientListMembersID { get; set; } [DataMember] public string PatientLastName { get; set; } [DataMember] public string PatientFirstName { get; set; } [DataMember] public DateTime? PatientDateOfBirth { get; set; }
public DataModel(string id, string first, string last, DateTime date) { PatientListMembersID = id; PatientFirstName = first; PatientLastName = last; PatientDateOfBirth = date; } } }
Here is my Controller and the way the data is added.
The first 2 items will display the correct date in the grid but consol.log will show the date as 12/31/2012.
public class DefaultController : Controller {
public ActionResult Index() {
var members = new List<DataModel>();
members.Add(new DataModel("1", "Fred", "Test", new DateTime(2013, 1, 1)));
members.Add(new DataModel("2", "Jane", "Test", new DateTime(2013, 1, 1).ToUniversalTime()));
members.Add(new DataModel("3", "Will", "Test", new DateTime(2013, 1, 1, 23, 0, 0)));
return View(members.AsQueryable());
}
Here is my View
@using DateTestMVC.Models
@using Infragistics.Web.Mvc
@model IEnumerable<DataModel>
@Scripts.Render("~/bundles/modernizr")
@Scripts.Render("~/bundles/jquery")
@Scripts.Render("~/bundles/jqueryui")
@Scripts.Render("~/bundles/infragistics.loader")
@(Html.Infragistics().Loader()
.ScriptPath(Url.Content("~/Scripts/Infragistics/"))
.CssPath(Url.Content("~/Content/Infragistics/"))
.Resources("igCombo,igGrid.Filtering")
.Theme("infragistics")
.Render()
)
@{ ViewBag.Title = "Index"; }
<h2>Grid</h2>
<div>
@(@Html.Infragistics().Grid<DataModel>()
.ID("grid").PrimaryKey("PatientListMembersID")
.LoadOnDemand(false).AutoGenerateColumns(false).AutoGenerateLayouts(false).EnableUTCDates(true)
.EnableHoverStyles(true).RenderCheckboxes(true).LocalSchemaTransform(true).AutoCommit(true)
.Columns(columns => {
columns.For(x => x.PatientListMembersID).Hidden(true);
columns.For(x => x.PatientLastName).Width("100").HeaderText("Last Name");
columns.For(x => x.PatientFirstName).Width("100").HeaderText("First Name");
columns.For(x => x.PatientDateOfBirth).DataType("date").Format("date").Width("100").HeaderText("DOB");
})
.Features(feature => {
feature.Sorting().Mode(SortingMode.Single);
feature.Selection().Mode(SelectionMode.Row).MultipleSelection(true);
feature.RowSelectors().EnableCheckBoxes(true).EnableRowNumbering(false);
feature.Resizing().AllowDoubleClickToResize(true);
.DataSource(Model)
.DataBind()
.Width("400")
.Height("500")
.Render())
</div>
<script type="text/javascript" language="javascript">
$.ig.loader(function () {
var grid = $('#grid');
if (grid) {
var igGrid = grid.data("igGrid");
var records = igGrid.dataSource.dataView();
var recordCount = records.length;
for (var idx = 0; idx < recordCount; idx++) {
var record = records[idx];
console.log(record.PatientFirstName, record.PatientDateOfBirth);
});
</script>
Hello Ddally,
I have heard back from the development team that Javascript Date objects are always created in the client's timezone, the Grid uses a formatter function to display them in UTC. So you can use the same function to get a string representing the Date in UTC
$.ig.formatter($("#grid").data("igGrid").dataSource.dataView()[0].PatientDateOfBirth, "date", "dateTime", true, true);
I you use MVC databinding logic the server will send offsets for each DateTime object in the data source. These are present in the metadata property of the dataSource.
$("#grid").data("igGrid").dataSource._metadata
Please let me know if you have any further questions regarding this matter.
It seems that the grid should do this automatically. If I put a date into the grid and then ask the grid for the record I Expect the record to be accurate
It also does not work
Nevermind, it looks like the formatter will spit out a valid date
I have opened a support request(CAS-110970-B0L6H5) for this forum post so we may research this behavior further. Please use the following link to log onto your account at Infragistics.Com:
https://es.infragistics.com/my-account/support-activity
Once you are logged onto your account, go to My Support Activity to view the progress of this support request. An update will be sent to you in the support request with any new information we find.
Please let me know if you have any questions.
Looks like for null dates it is adding  
It does spit out a date, it just spits out an invalid formatted date according the the javascript deserializer