The following code exemplifies my real world scenario. The data flushed by ResultStore is "mal formatted". The Date's millisecond does not have a XXX format.
<!DOCTYPE html>
<html>
<head runat="server">
</head>
<body>
<ext:ResourceManager runat="server" />
<ext:GridPanel Title="Records" Frame="false" Width="500" runat="server">
<Store>
<ext:Store runat="server">
<Proxy>
<ext:AjaxProxy Url="/Example/LoadFakeRecords/">
<ActionMethods Read="POST" />
<Reader>
<ext:JsonReader Root="data" />
</Reader>
</ext:AjaxProxy>
</Proxy>
<Model>
<ext:Model runat="server">
<Fields>
<ext:ModelField Name="ID" Type="String" />
<ext:ModelField Name="Birthdate" Type="Date" DateFormat="d/m/Y H:i:s">
<Convert Handler="return Ext.util.Format.date(value, 'd/m/Y H:i:s');" />
</ext:ModelField>
</Fields>
</ext:Model>
</Model>
<Sorters>
<ext:DataSorter Property="Common" Direction="ASC" />
</Sorters>
</ext:Store>
</Store>
<ColumnModel runat="server">
<Columns>
<ext:RowNumbererColumn runat="server" />
<ext:Column Text="ID" DataIndex="ID" runat="server"/>
<ext:Column Text="Birthdate" DataIndex="Birthdate" Width="300" runat="server"/>
</Columns>
</ColumnModel>
</ext:GridPanel>
</body>
</html>
public class ExampleController : System.Web.Mvc.Controller
{
public ActionResult Index()
{
return View();
}
public StoreResult LoadFakeRecords()
{
List<Person> lst = new List<Person>();
lst.Add(new Person
{
ID = 1,
Birthdate = new DateTime(2013, 05, 17, 10, 11, 12, 13),
});
lst.Add(new Person
{
ID = 2,
Birthdate = new DateTime(2013, 05, 17, 10, 11, 12, 200),
});
return new StoreResult(lst, lst.Count());
}
}
public class Person
{
public int ID { get; set; }
public DateTime Birthdate { get; set; }
}
It's possible to overcome this issue by defining a new StoreResult class, that uses JSONDateTimeJsonConverter to flush Date's millisecond formatted accordingly.
public class SmartStoreResult : StoreResult
{
public SmartStoreResult(object data, int totalCount) :
base(data, totalCount) { }
public override void ExecuteResult(ControllerContext context)
{
NodeCollection nodes = this.Data as NodeCollection;
StoreResponseData storeResponse = new StoreResponseData(this.IsTree || nodes != null);
if (nodes != null)
{
storeResponse.Data = ((NodeCollection)this.Data).ToJson();
}
else
{
storeResponse.Data = JSON.Serialize(this.Data, new List<JsonConverter> { new JSONDateTimeJsonConverter { RenderMilliseconds = true } });
}
storeResponse.Total = this.Total;
storeResponse.Success = this.Success;
storeResponse.Message = this.Message;
storeResponse.Return();
}
}
public class ExampleController : System.Web.Mvc.Controller
{
public ActionResult Index()
{
return View();
}
public SmartStoreResult LoadFakeRecords()
{
List<Person> lst = new List<Person>();
lst.Add(new Person
{
ID = 1,
Birthdate = new DateTime(2013, 05, 17, 10, 11, 12, 13),
});
lst.Add(new Person
{
ID = 2,
Birthdate = new DateTime(2013, 05, 17, 10, 11, 12, 200),
});
return new SmartStoreResult(lst, lst.Count());
}
}
I would like to know what do you think about this approach.
Thanks in advance