This is a migrated thread and some comments may be shown as answers.
All Dates show up as "/Date(1293868800000)/"
3 Answers 203 Views
This is a migrated thread and some comments may be shown as answers.
Jeremy
Top achievements
Rank 1
Jeremy asked on 08 Feb 2012, 08:01 PM
This is probably something very silly and simple, but all of my dates ignore the format property and show up as "/Date(1293868800000)/"

This is a .NET project connecting to a web service.  All other columns show up fine.



Some sample code:

$("#grid").kendoGrid({
 
              columns: [
                  { title: "Action", command: "destroy" },
                  { field: "TaskName", title: "Task Name" },
                  { field: "UserList", title: "Assigned to" },
                  { field: "GroupName", title: "Group" },
                  { field: "StatusName", title: "Status" },
                  { field: "DueDate", title: "Due Date", format: "{0:dd/MMMM/yyyy}" },
                  { field: "CompletedDate", title: "Completed Date", format: "{0:dd/MMMM/yyyy}" },
                  { field: "Notes" }
              ],


and the web service is as follows:

<WebMethod()> _
Public Function Read() As List(Of TaskViewmodel)
 
    Using Context As New TFE.TFEEntities
 
        Try
 
            Return Context.JobTasks.Select(Function(task) New TaskViewmodel With {.TaskID = task.JobTaskID, .TaskName = task.TaskName, .UserList = "Comming Soon...", .GroupID = task.GroupID, .GroupName = task.Group.Name, .StatusID = task.StatusID, .StatusName = task.JobTaskStatus.Name, .DueDate = task.DueDate, .CompletedDate = task.CompletedDate, .Notes = task.Notes}).ToList()
 
        Catch ex As Exception
            Throw ex
        End Try
 
    End Using
 
End Function



3 Answers, 1 is accepted

Sort by
0
Ralph
Top achievements
Rank 1
answered on 09 Feb 2012, 10:37 PM
It's the number of milliseconds since epoch. Take a look at the following StackOverflow question to solve this issue.
0
Brady
Top achievements
Rank 1
answered on 18 Apr 2012, 05:28 PM
I just encountered this problem as well. .NET seems to be idiosyncratic (everyone is) in the JSON serialization of date values. I solved it using this code in my dataSource:

schema: {
    data: function (data) {
        for (var i = 0; i < data.Items.length; i++) {
            var item = data.Items[i];
            if (item.DateCompleted) {
                item.DateCompleted = new Date(parseInt(item.DateCompleted.substr(6)));
            }
        }
        return data.Items;
    },
    model: {
        id: "Id",
        fields: {
            Name: { type: "string" },
            DateCompleted: { type: "date", format: "{0:dd/MMMM/yyyy}" },
            Result: { type: "number" }
        }
    }
}
 
My grid now edits the date cells correctly, but still ignores my set format string as uses a long date format anyway.
0
Michael
Top achievements
Rank 1
answered on 12 Sep 2015, 11:25 PM

I had a similar problem with using a Kendo UI Grid with my MVC controller method.

Perhaps the problem is DateTime is an object, and JSON serialization converts it to an unreadable but de-serializable string. So the solution I had with my case is I converted the DateTime properties to string using the "ToString" method at the server method.

 
E.g.

[HttpGet]
public JsonResult KendoUIWidgetRead()
{
    IEnumerable<Newsletters> ie = GetNewsletters();

      

    //Selecting only part of the columns available, instead of the whole range returned by the GetNewsletters() function
    IEnumerable<object> result = ie.Select(a => new
    {
        Title = a.Title,
        Subtitle = a.Subtitle,
        ShowAfter = a.CreateTime.ToString("dd/MM/yyyy") //If the property is a DateTime object, you MUST convert it to a string, otherwise it would not display properly
    });
 
    JsonResult jr = Json(result, JsonRequestBehavior.AllowGet);
    return jr;
}

Tags
Grid
Asked by
Jeremy
Top achievements
Rank 1
Answers by
Ralph
Top achievements
Rank 1
Brady
Top achievements
Rank 1
Michael
Top achievements
Rank 1
Share this question
or