This is a migrated thread and some comments may be shown as answers.

Custom format for datetime column with inline editing

6 Answers 786 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Alexandra
Top achievements
Rank 1
Alexandra asked on 05 Jul 2017, 11:37 AM

I have a grid with a datetime column that needs to be batch edited. The column has to be custom formatted that is different than the default format of the culture.

The code looks something like:

columns.Bound(product => product.DateField).Format("{0:dd.MM.yyyy}")

 

Also I have added the templates from Kendo src for Date/DateTime.  @(Html.Kendo().DateTimePickerFor(m => m))

 

When I edit I always get the message "The field DateField must be a date".

I even tried to change the template with .ParseFormats(new string[] { "dd.MM.yyyy" }) but still I get the same message.

 

Can the datetimepicker be used in editing grid with custom format?

6 Answers, 1 is accepted

Sort by
0
Alex Hajigeorgieva
Telerik team
answered on 07 Jul 2017, 10:56 AM
Hi Alexandra,

I tried to reproduce the same behaviour to no avail in one of our demos which I modified to be as close to your scenario as possible:

http://dojo.telerik.com/aZESIv/2

Could you please advise why the Kendo UI DateTimePicker widget is used (as opposed to the DatePicker widget) when the time portion will not be shown to the user?

I suggest setting the Format() of the DatePicker:

.Format("dd.MM.yyyy")

Let me know how you get on.

Regards,
Alex Hajigeorgieva
Progress Telerik
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data (charts) and form elements.
0
Sebastian
Top achievements
Rank 1
answered on 12 Jul 2017, 06:34 AM

Hi Alex,

I work with Alexandra and we could still not make the date picker work with a different format work.

We have found a project http://www.telerik.com/support/code-library/using-utc-time-on-both-client-and-server-sides but this does work if the machine has a different culture than en. If the machine has the English format the project works without any change.

So we have adapted the project to use a different format on the English machine and when we try to edit the date the same message appears. "The field BithDate must be a date"

Attached is the modified project where we changed:

In DateTime editor we used @(Html.Kendo().DateTimePickerFor(m => m).Format("dd-MMM-yyyy")) and

in Index.cshtml we changed the columns.Bound(c=>c.BirthDate).Format("dd-MMM-yyyy")

 

0
Accepted
Stefan
Telerik team
answered on 14 Jul 2017, 06:25 AM
Hello Sebastian, Alexandra,

Thank you for the runnable example.

After additional investigation, indeed the issue occurs due to the different format set on the DateTime editor.

In this scenario, the built-in validation rule has to be overridden. Please check the following article demonstrating this:

http://docs.telerik.com/aspnet-mvc/troubleshoot/troubleshooting-validation#globalized-dates-and-numbers-are-not-recognized-as-valid-when-using-the-validator

I hope this will help to achieve the desired result.

Regards,
Stefan
Progress Telerik
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data (charts) and form elements.
0
Alexandra
Top achievements
Rank 1
answered on 19 Jul 2017, 10:14 AM

Hello Stefan,

Thank you for the investigation and the suggestion, however our customer does not want for the moment custom format for dates. The default ones are good. But who know what the future holds so I do have 2 questions though:

1. On the link the example uses still kendo.parseDate. Should I still use this? (I did some debugging the this method was failing on the MVC project)

2. Why did Alex dojo example was working while the MVC was failing? (I wanted to debug Alex's dojo but there is no link to the unminified version of the telerik scripts)

Thank you,

Alexandra

0
Alex Hajigeorgieva
Telerik team
answered on 21 Jul 2017, 08:52 AM
Hi Alexandra,

If I understand you correctly, you do not wish to use custom date formats. If this is the case, then the answer to the first question is no, there is no need to use the approach from the article.

1. On the link, the example uses still kendo.parseDate. Should I still use this? 

This is only needed for custom formats. The approach you need to take when using UI for MVC - is to match the culture on both the client and the server, otherwise, the validation will fail. One of our official demos shows dynamic culture changes:

http://demos.telerik.com/aspnet-mvc/grid/globalization

Client side culture is in the first tab, globalization.cshtml and the controller code is in the second tab:



Regarding the second question:

2. Why did Alex dojo example was working while the MVC was failing? 

My demo was working because validation was only handled on the client in this case. 

More information about keeping the server and client cultures in tune is available at:

http://docs.telerik.com/aspnet-mvc/getting-started/globalization

Kind Regards,
Alex Hajigeorgieva
Progress Telerik
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data (charts) and form elements.
0
Alexandra
Top achievements
Rank 1
answered on 21 Jul 2017, 11:17 AM

Hi Alex,

At a better look at the page found that the recommanded way for custom format in MVC is kendo.parseDate(input.val(), "dd/MM/yyyy") !== null;. I must have missed that.

Tags
Grid
Asked by
Alexandra
Top achievements
Rank 1
Answers by
Alex Hajigeorgieva
Telerik team
Sebastian
Top achievements
Rank 1
Stefan
Telerik team
Alexandra
Top achievements
Rank 1
Share this question
or