New to Telerik UI for ASP.NET MVC? Download free 30-day trial

Events

For a complete example on the Timeline events, refer to the demo on using the events of the Timeline in ASP.NET MVC.

You can provide an event handler through its JavaScript function name, or by specifying an inline function in a template.

Handling Events by Handler Name

The following example demonstrates how to subscribe to events by using a handler name.

    @(Html.Kendo().Timeline<MyApp.Models.TimelineEventModel>()
        .Name("Timeline")
        .Events(ev =>
         {
            ev.Change("onChange");
            ev.Navigate("onNavigate");
            ev.DataBound("onDataBound");
            ev.ActionClick("onActionClick");
         })
        .DataDateField("EventDate")
        .DataDescriptionField("Description")
        .DataSubTitleField("Subtitle")
        .DataTitleField("Title")
        .DataImagesField("Images")
        .DataActionsField("Actions")
        .DataSource(dt => dt.Read("GetTimelineData", "Timeline")) // see the first example in this article for a sample data source
    )

    <script>
        function onChange(e) {
                    console.log("OnChange: " + e.dataItem.Title);
                }

                function onNavigate(e) {
                    console.log("OnNavigate: " + e.action);
                }

                function onActionClick(e) {
                    console.log("OnActionClick: " + e.element.text());
                }

                function onDataBound(e) {
                    console.log("OnDataBound: " + e.sender.dataSource.view().length);
                }
    </script>

Handling Events by Template Delegate

The following example demonstrates how to subscribe to events by using a template delegate.

@(Html.Kendo().Timeline<MyApp.Models.TimelineEventModel>()
    .Name("Timeline")
    .Events(e =>
        e.Change(@<text>
            function(e) {
                // Handle the Change event inline.
            }
        </text>)
       .Navigate(@<text>
            function(e) {
                // Handle the Navigate event inline.
            }
        </text>)
     )
    .DataDateField("EventDate")
    .DataDescriptionField("Description")
    .DataSubTitleField("Subtitle")
    .DataTitleField("Title")
    .DataImagesField("Images")
    .DataActionsField("Actions")
    .DataSource(dt => dt.Read("GetTimelineData", "Timeline")) // see the first example in this article for a sample data source
)

See Also

In this article