I'm trying to format my DateTime
object in my Kendo ListView Template but the suggested kendo.toString
method doesn't seem to work for me.
I've cut out a lot of code that doesn't relate to my problem to make it a little more simple to understand.
I have a Kendo DataSource
that looks like the following:
contactDataSource: new kendo.data.DataSource({
transport: {
read: {
url: "/baa/contact/getcontacts",
dataType: "json",
type: "GET"
}
},
schema: {
model: {
id: "Id",
fields: {
Id: { type: "number", editable: false, nullable: true },
CompanyName: { type: "string" },
ContactName: { type: "string" },
ContactPhone: { type: "string" },
ContactEmail: { type: "string" },
ImageUrl: { type: "string" },
Website: { type: "string" },
RecentBaas: [
{
Name: { type: "string" },
StatusDisplay: { type: "string" },
Status: { type: "number" },
LastModDate: { type: "date" }
}
]
}
}
}
})
And then I have a template on my view that looks like the following:
<script type="text/x-kendo-templ" id="contactTemplate">
<div class="row">
<div class="col-md-12">
# for (var i = 0; i < RecentBaas.length; i++) { #
# if (RecentBaas[i].Status == 1) { #
<div class="alert alert-success" role="alert">
<p>#=kendo.toString(RecentBaas[i].LastModDate, "F")#</p>
</div>
# } #
# } #
</div>
</div>
</script>
I'm not getting any errors in my console when I load this page, but the date is not formatted at all. It still just shows as /Date(1461203814927)/
for example.
I've read the Kendo Documentation on how to use the toString
function to format DateTime
objects and as far as I can tell I'm doing everything right. But maybe I'm still missing something?
New to Kendo UI for jQuery ? Download free 30-day trial The purpose of date formatting is to convert the Date object to a human readable string by using the culture-specific settings. The kendo.format and kendo.toString methods support standard and custom date formats.
Kendo UI Templates trade convenient syntax sugar for improved performance, which distinguishes it from other templating JavaScript libraries. The Templates is part of Kendo UI for jQuery, a professional grade UI library with 110+ components for building modern and feature-rich applications. To try it out sign up for a free 30-day trial.
The Kendo UI Templates use a simple templating syntax called hash templates. With this syntax, the # (hash) sign is used to mark areas in a template that should be replaced by data when the template is executed. The # character is also used to signify the beginning and end of custom JavaScript code inside the template.
Download free 30-day trial The purpose of date formatting is to convert the Date object to a human readable string by using the culture-specific settings. The kendo.format and kendo.toString methods support standard and custom date formats.
Please try with the below code snippet.
<script type="text/x-kendo-templ" id="contactTemplate">
<div class="row">
<div class="col-md-12">
# for (var i = 0; i < RecentBaas.length; i++) { #
# if (RecentBaas[i].Status == 1) { #
<div class="alert alert-success" role="alert"> <p>#=kendo.toString(kendo.parseDate(RecentBaas[i].LastModDate), 'yyyy-MM-dd')#</p>
</div>
# } #
# } #
</div>
</div>
</script>
Let me know if its not working
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With