Events
You can subscribe to the available DataSource events and further customize the behavior of the DataSource.
Handling by Handler Name
The following example demonstrates how to subscribe to events by a handler name.
@(Html.Kendo().DataSource<ProductViewModel>()
.Name("dataSource1")
.Ajax(dataSource => dataSource
.Events(ev => ev.RequestStart("onRequestStart"))
.Read(read => read.Action("Products_Read", "DataSource"))
... // Additional configuration
)
)
<script>
function onRequestStart(e){
// Handle the RequestStart event that triggers the DataSource makes a request to the remote service.
}
</script>
<kendo-datasource name="dataSource1" type="DataSourceTagHelperType.Ajax" on-request-start="onRequestStart">
<transport>
<read url="@Url.Action("Products_Read", "DataSource")" />
</transport>
<!-- Additional configuration -->
</kendo-datasource>
<script>
function onRequestStart(e){
// Handle the RequestStart event that triggers when the DataSource makes a request to the remote service.
}
</script>
Handling by Template Delegate
The following example demonstrates how to subscribe to events by a template delegate.
@(Html.Kendo().DataSource<ProductViewModel>()
.Name("dataSource1")
.Ajax(dataSource => dataSource
.Read(read => read.Action("Products_Read", "DataSource"))
.Events(e => e.RequestStart(@<text>
function() {
// Handle the RequestStart event inline.
}
</text>)
)
... // Additional configuration
)
)
<kendo-datasource name="dataSource1" type="DataSourceTagHelperType.Ajax" on-request-start="function() {
// Handle the RequestStart event inline.
}">
<transport>
<read url="@Url.Action("Products_Read", "DataSource")" />
</transport>
<!-- Additional configuration -->
</kendo-datasource>