Reputation: 20
Is there any way to get the kendo DataSource to use a different date format than the selected culture defines?
I have a german and english front end. But my datasource always provides dates in english format, which leads to an error in the german version, as the datasource expects the date in german format as defined in the culture.
Can a define a format in the field definition of the datasource model?
Update: The datasource of my kendo scheduler looks like that:
dataSource: {
transport: {
read: {
url: "dates.json",
dataType: "json"
}
},
schema: {
model: {
id: 'taskId',
fields: {
taskId: { type: "number", from: "ID" },
ownerId: { type: "number", from: "Category" },
title: { type: "string", from: "Title" },
description: { type: "string", from: "Description" },
Location: { type: "string" },
start: { type: "date", from: "EventDate" },
end: { type: "date", from: "EndDate" },
isAllDay: { type: "boolean", from: "AllDayEvent" },
}
}
}
},
The format of the event date in my datasource is: dd/MM/yyyy HH:mm. The british english culture I use for my english front end uses exactly this format. The german culture uses dd.MM.yyyy HH:mm.
Upvotes: 0
Views: 2096
Reputation: 1719
You should use a server-side format that doesn't depend on the culture you are using in the UI. Using an English format like you are actually using in the server-side introduces problems like the one you are facing and is not API-friendly.
If you return the date in ISO 8601 you can be sure the date will be properly parsed in your client side. Also if you don't mind about timezones, you can use the YYYY-MM-DD HH:mm:ss format, that is also a standard in computing.
If you cannot change the file you are fetching these dates from, have a look at this thread. It seems there are some workarounds using templating + kendo.parseDate, but the good solution is to use a standard culture independent date format.
Upvotes: 1