
Christian Sandöy
Top achievements
Rank 2
Christian Sandöy
asked on 21 Nov 2018, 03:44 PM
this template does not work
<column field="Dato" title="Dato" template="#= (Dato == null) ? ' ' : kendo.toString(Dato, 'dd-MM-yyyy') #" />
t works in a html helper grid
t shows the time also
3 Answers, 1 is accepted
0

Christian Sandöy
Top achievements
Rank 2
answered on 22 Nov 2018, 09:51 AM
I change it to this
<column field="Dato" title="Dato" template="#= (Dato == null) ? ' ' : kendo.toString(kendo.parseDate(Dato), 'dd-MM-yyyy') #" />
This works
Why does html helper template not work in tag helper template???
2
Hello Christian,
The DataSource in the HTML helper Grid can determine the field types automatically based on the Grid model.
In the tag helper, there is no such model assignment, so the field types should be declared explicitly for fields different than strings. This is noted in the documentation here: Configuration.
Without such declaration, all fields are treated as strings and that is why you first needed to parse the Date before you could format it.
Regards,
Tsvetina
Progress Telerik
The DataSource in the HTML helper Grid can determine the field types automatically based on the Grid model.
@(Html.Kendo().Grid<Kendo.Mvc.Examples.Models.ProductViewModel>()
In the tag helper, there is no such model assignment, so the field types should be declared explicitly for fields different than strings. This is noted in the documentation here: Configuration.
<
kendo-grid
name
=
"grid"
height
=
"550"
>
<
datasource
type
=
"DataSourceTagHelperType.Custom"
custom-type
=
"odata"
page-size
=
"20"
>
<
transport
>
</
transport
>
<
schema
>
<
model
>
<
fields
>
<
field
name
=
"OrderID"
type
=
"number"
></
field
>
<
field
name
=
"OrderDate"
type
=
"Date"
></
field
>
</
fields
>
</
model
>
</
schema
>
</
datasource
>
<
groupable
enabled
=
"true"
/>
<
sortable
enabled
=
"true"
/>
<
filterable
enabled
=
"true"
/>
<
pageable
button-count
=
"5"
refresh
=
"true"
page-sizes
=
"new int[] { 5, 10, 20 }"
>
</
pageable
>
<
columns
>
<
column
field
=
"OrderID"
width
=
"120"
/>
<
column
field
=
"OrderDate"
title
=
"Order Date"
format
=
"{0:MM/dd/yyyy}"
/>
<
column
field
=
"ShipName"
title
=
"Ship Name"
width
=
"300"
/>
<
column
field
=
"ShipCity"
title
=
"Ship City"
width
=
"250"
/>
</
columns
>
</
kendo-grid
>
Without such declaration, all fields are treated as strings and that is why you first needed to parse the Date before you could format it.
Regards,
Tsvetina
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0

Christian Sandöy
Top achievements
Rank 2
answered on 26 Nov 2018, 01:43 PM
Thanks it works now