Date formatter

Oct 31, 2012 at 6:14 PM

Imagine u have a date format column working on a clientarray way, so I want to send all data from an jqgrid at the same time.


There is a problem with date column when It´s data I post first time on loading.. because u can see ok formatted but internally the data continues like  "/Date(1718800000)" so its what u get when u get data from jqgrid, that it´s set by default. All data date inserted or modified or even canceled are ok, but not those which u didnt try to modify.

Imagine Load this data, this is what you get with get with .jqGrid('getGridParam','data')

ROW 1  show 2012-02-01 hidden value (/DATE(5712765210000)) if u dont do anything

ROW 2 show 2012-02-01 hidden value (2012-02-01) if u insert, edit or try to edit and cancel the row.


I needed to change BINDER to work properly adding this one


 if (value.AttemptedValue.IndexOf("/Date(") >= 0)            {

string dataDate = value.AttemptedValue.Replace("/Date(", "").Replace(")", "");                date= new DateTime(1970, 1, 1).AddTicks(Convert.ToInt64(dataDate) * 10000);


I dont know if there should  be another format that set values on text (depending on the culture), or should init hidden data once u load (jqgrid problem)...

Anyway it could be convenience to have antoher formats to show date and time at the same time...



Nov 1, 2012 at 3:15 PM
Edited Nov 1, 2012 at 3:25 PM

Well dates are one of those things that gets very complicated in JSON context. The standard JSON date object format can be only read, not created by jqGrid. There is a good reason for that - this format contains timezone information which is lost by string representation in most cases (I also suggest here that you should check if your logic is properly handling those timezones, using JavaScriptSerializer or JSON.NET for deserializing date objects only might be better move here).

So as long as you are sending actual date objects from server side there is no way to solve this as this is how date object looks in JSON (you can always send strings from server instead of dates) - even after moving to JSON.NET and ISO dates the issue of timezone aspect will remain.

Now if it comes to displaying time this can be easly done with SourceFormat and OutputFormat properties of JqGridColumnFormatterAttribute:

 [JqGridColumnFormatter(JqGridColumnPredefinedFormatters.Date, SourceFormat = "d.m.Y G:i:s", OutputFormat = "d.m.Y G:is")]

This will give you time in display and in the posted values which has been "touched" by the user (notice that jqGrid is using PHP formatting here).