The filter for a DateTime column of an ASP.NET MVC grid is in the US format of MM/DD/YYYY HH:MM. I would like the date to be shown in the UK format of DD/MM/YYYY. I have seen similar requests, but these are from 2013.
Are there any newer approaches to getting the filter to show the date format as DD/MM/YYYY?
Regards,
Shawn
1 Answer, 1 is accepted
A possible solution is to set the client culture to English culture. The following article illustrates how to change the client culture step by step:
Another solution is to set date format by customizing the filter widget. There are two approaches depending on the mode of the filtering.
1. For filter in mode row, the column should be configured as follows:
columns.Bound(x => x.Birthday).Format(
"{0: MM/dd/yyyy}"
).Filterable(x => x.Cell(y => y.Template(
"datePicker"
)));
And the DatePicker function that builds the customized filter widget should look like the function below:
function
datePicker(args) {
args.element.kendoDatePicker({
format:
"dd/MM/yyyy"
});
}
2. When using a filter in mode menu, the column should be configured as follows:
columns.Bound(x => x.Birthday).Format(
"{0: MM/dd/yyyy}"
).Filterable(x => x.UI(
"datePicker"
));
The following code block contains the DatePicker function:
function datePicker(element) {
element.kendoDatePicker({
format:
"dd/MM/yyyy"
});
}
Regards,
Georgi
Progress Telerik
Georgi,
The filter in mode menu option worked for me. Thank you once again for the help.
Regards,
Shawn
Hi Georgi,
I tried filter in mode row, when i tried to filter by date no data is returned.
Hi Visvak,
Have in mind that if you use the equals operator, also the time portion should match. Could you please test with some other operator for example after?
Regards,
Georgi
Progress Telerik
Our thoughts here at Progress are with those affected by the outbreak.
Hi Team,
How to set the default operator for datepicker filter.
For text box i tried b.Filterable(f => f.Enabled(enable).Cell(c => c.Operator("contains").SuggestionOperator(FilterType.Contains))); - this works for textbox.
For datepicker i tried b.Filterable(f => f.Enabled(enable).Cell(c => { c.Template("datePickerFilter").Operator("equals"); })) - this does not work;
the default operator must be equal. if i select the equal manually the date filter works .
Please let me know how to set the default operator for datepicker.
I have attached the screenshot . please refer it .
Thank you in Advance.
Hello Visvak,
You should simply replace "equals" with "eq".
e.g.
b.Filterable(f => f.Enabled(enable).Cell(c => { c.Template("datePickerFilter").Operator("eq"); }))
Regards,
Georgi
Progress Telerik
Five days of Blazor, Angular, React, and Xamarin experts live-coding on twitch.tv/CodeItLive , special prizes and more, for FREE?! Register now for DevReach 2.0(20).
Hi Georgi,
I tried that also but it did not work. if i change to "eq" getting string error , it is considering the date must be a string.
Hi Georgi,
I have attached the error screen shot .
Hello Visvak,
I have tested the same and it seems to work correctly on my end.
Configuration:
columns.Bound(p => p.OrderDate).Format("{0:MM/dd/yyyy}").Filterable(f => f.Cell(c => { c.Operator("neq"); }));
Operators drop down:
Does the error occur during compilation or upon filter? Would it be possible to share a sample with me where the issue can be replicated?
Regards,
Georgi
Progress Telerik
Five days of Blazor, Angular, React, and Xamarin experts live-coding on twitch.tv/CodeItLive , special prizes and more, for FREE?! Register now for DevReach 2.0(20).