I want to build a Kendo UI Grid with format date dd//MM/yyyy. However, all questions that I found about this, it were resolved with code Format("{0:d}");. So, I have tried like a code below:
GridBoundColumnBuilder<TModel> builder = par.Bound(field.Name);
switch (field.Type.Type)
{
case CType.Boolean:
builder = builder.ClientTemplate(string.Format("<input type='checkbox' #= {0} ? checked='checked' : '' # disabled='disabled' ></input>", field.Name));
break;
case CType.Datetime:
builder = builder.Format("{0:d}");
break;
case CType.Decimal:
case CType.Double:
builder = builder.Format("{0:0.00}");
break;
}
Another formats is works fine, just DateTime do not works.
I had this result for Datetime = /Date(1377020142000)/
I don't know about Kendo UI but it looks to me like you want to pass a string formatted date rather than a DateTime object.
The
/Date(...)/
output looks like a JSON formatted date from .Net.I would convert the date to a string using somthing like
myDateTime.ToString("dd/MM/yyyy");
before passing it to the control.The other solutions were close but no cigar... Here's what worked for me:
The core issue is documented really well here. Combining the answers there with other stuff I found, here's what I had to do to get it to work on my project.
In the C# code:
Then, create a javascript function:
It's a bit of a kluge, but works.
Try instead this,this will work.
Can also use:
As in http://docs.telerik.com/kendo-ui/framework/globalization/dateformatting
There may be some other options in System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat that might work for you if that is not what you want.