0
votes

I have column in the kendo Grid which has data type TimeSpan (ASP.NET). I have two problems:

  1. Firstly, it is not formatting the time in the format HH:mm
  2. Secondly, when I filter I get the error - conversion from string to timespan failed.

The strip down version of code looks like

@(Html.Kendo().Grid<SomeModel>()
.Name("Grid")
.Columns(colums => 
{
   columns.Bound(c => c.StartTime).Title("Start Time"); // TimeSpan data type 
})
2

2 Answers

0
votes

1 You should use a client template to display the timespan column:

columns.Bound(p => p.StartTime).ClientTemplate("#= StartTime.Minutes #:#= StartTime.Seconds #:#= StartTime.Milliseconds #");

for more details please refer to: http://www.telerik.com/forums/working-with-timespans

2 You should create a custom function that will be passed as filter for datasource if client side filtering is needed http://www.telerik.com/forums/how-to-define-a-custom-filter-operator and here you will need also a timepicker or a custom editor to allow that will be displayed when the user will press the filter button http://demos.telerik.com/kendo-ui/grid/filter-menu-customization

0
votes

Create a computed property on the server like so...

public string ComputedTime {
set{
var time = StartTime.ToShortDateString();

// extra work here
return time;
}
}

Then in razor

@(Html.Kendo().Grid<SomeModel>()
.Name("Grid")
.Columns(colums => 
{
   columns.Bound(c => c.ComputedTime).Title("Start Time"); // TimeSpan data type 
})