Hello.
I need some assistance with a grid where I'm attempting to work with a timespan value.
This is my grid code right now:
I made a custom editor helper for editing the timespan in the way i'd like to, and it looks like this:
First problem, I need to be able to bind the Timespan Helper to the actual TimeSpan values. I understand that Javascript doesn't support TimeSpan, and converts it to something like this:
How can I modify my helper to manipulate this Json object instead and get it to update the values in the objects that I'm sending back to the database.
Second problem is, when I attempt to create a new object inline, I get a Javascript error telling me that Time is not defined.
If I remove the ClientTemplate from the Time column in the grid code I don't get that error. The ClientTemplate code is something I found on these forums, but in that example they only used Minutes, Seconds like this:
But when I tried that I got a "Minutes is not defined" error.
Any advice on how to work around this would be cool.
I've considered just making a TimeSpan helper class with int properties for the values I need to edit and convert it back and forth in my .net code. But it depends on how much work it will be to get what I already have working, it would be nice to be able to work with the timespan objects in the kendo grid.
I need some assistance with a grid where I'm attempting to work with a timespan value.
This is my grid code right now:
<
div
class
=
"twelve columns"
>
@(Html.Kendo().Grid<
TimelineMarker
>()
.Name("TimelineMarkers")
.Columns(columns =>
{
columns.Bound(p => p.Order).Width(60);
columns.Bound(p => p.Time).ClientTemplate("#= Time.Minutes #:#= Time.Seconds #:#= Time.Milliseconds #");
columns.Bound(p => p.Text);
columns.Bound(p => p.Type);
columns.Command(command => { command.Edit(); command.Destroy(); }).Width(200);
})
.ToolBar(toolbar => toolbar.Create())
.Editable(editable => editable.Mode(GridEditMode.InLine))
.Pageable()
.Sortable()
.Scrollable()
.DataSource(dataSource => dataSource
.Ajax()
.Events(events => events.Error("error_handler"))
.Model(model =>
{
model.Id(p => p.TimelineMarkerId);
model.Field(x => x.Media.Name).Editable(false);
model.Field(x => x.MediaId).DefaultValue(Model.Media.MediaId);
})
.Create(update => update.Action("TimelineMarker_Create", "MediaAdminService"))
.Read(read => read.Action("TimelineMarker_Read/"+Model.Media.MediaId, "MediaAdminService"))
.Update(update => update.Action("TimelineMarker_Update", "MediaAdminService"))
.Destroy(update => update.Action("TimelineMarker_Destroy", "MediaAdminService"))
)
)
</
div
>
@model TimeSpan
@using Kendo.Mvc.UI
<
div
id
=
"timespanEditor"
>
<
div
class
=
"three columns"
>
@(Html.Kendo().IntegerTextBoxFor(m => m.Minutes)
.Name("timespanpickerMinute")
.Min(new TimeSpan(0, 0, 0).Seconds)
)
</
div
>
<
div
class
=
"three columns"
>
@(Html.Kendo().IntegerTextBoxFor(m => m.Seconds)
.Name("timespanpickerSecond")
.Min(new TimeSpan(0, 0, 0).Seconds)
)
</
div
>
<
div
class
=
"three columns"
>
@(Html.Kendo().IntegerTextBoxFor(m => m.Milliseconds)
.Name("timespanpickerMillisecond")
.Min(new TimeSpan(0, 0, 0).Seconds)
)
</
div
>
</
div
>
,
"Time"
:{
"Hours"
:0,
"Minutes"
:15,
"Seconds"
:14,
"Milliseconds"
:230,
"Ticks"
:9142300000,
"Days"
:0,
"TotalDays"
:0.01058136574074074,
"TotalHours"
:0.25395277777777775,
"TotalMilliseconds"
:914230,
"TotalMinutes"
:15.237166666666667,
"TotalSeconds"
:914.2299999999999}
Second problem is, when I attempt to create a new object inline, I get a Javascript error telling me that Time is not defined.
If I remove the ClientTemplate from the Time column in the grid code I don't get that error. The ClientTemplate code is something I found on these forums, but in that example they only used Minutes, Seconds like this:
ClientTemplate(
"#= Minutes #:#= Seconds #:#= Milliseconds #"
);
Any advice on how to work around this would be cool.
I've considered just making a TimeSpan helper class with int properties for the values I need to edit and convert it back and forth in my .net code. But it depends on how much work it will be to get what I already have working, it would be nice to be able to work with the timespan objects in the kendo grid.