Having spent may frustrating hours trying to solve this and now having found a solution, I thought that I would post my findings for the benefit of others.
Grid:
@(Html.Kendo().Grid<Models.Data.Database>
()
.Name("grid")
.Columns(columns =>
{
columns.Bound(p => p.Name).Title(language.TranslateSchema(Enums.Schema.ImportData_Database));
columns.Bound(p => p.Legacy).Title(language.TranslateSchema(Enums.Schema.ImportData_Legacy)).Width(100);
columns.Bound(p => p.TableCount).Title(language.TranslateSchema(Enums.Schema.ImportData_TableCount)).Width(100);
columns.Command(c => c.Custom("Select").TemplateId("SelectTemplate")).Width(75);
})
.HtmlAttributes(new { style = "height: 450px; font-size: 12px" })
.Scrollable()
.Selectable(s => s
.Mode(GridSelectionMode.Single)
.Type(GridSelectionType.Row))
.Pageable(pageable => pageable
.Refresh(true)
.PageSizes(true)
.ButtonCount(5))
.Sortable()
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(20)
.Model(model => model.Id(m => m.Name))
.Read(read => read.Action("Utility", "Index", new { handler = "DatabaseRead" }).Data("AntiForgeryToken"))
)
)
Template:
<script type="text/x-kendo-template" id="SelectTemplate">
<a class="btn btn-s-primary"
onclick="SelectRow(this)"
data-toggle="tooltip"
data-trigger="hover"
data-delay="{ show: 1000,hide: 0}"
data-placement="bottom"
role="button"
title="@language.Translate(Enums.Tooltip.Question_Text)">
<span class='glyphicon glyphicon-ok'></span>
</a>
</script>
Script:
<script type="text/javascript">
function SelectRow(e) {
var grid = $("#grid").data("kendoGrid");
var item = grid.dataItem($(e).closest("tr")[0]);
if (item != null && item != "undefined") {
$.ajax({
url: "/Utility/Index?handler=SelectDatabase&name=" + item.Name,
datatype: "json",
type: "GET"
});
}
}
</script>
Findings:
I scoured the web and tried many solutions based around 'grid.select()' to no avail. The main problem and the moment of enlightenment came when I clicked on the row before clicking the custom link. When you click on the row - that row is selected - when you only click on the custom link the row is not selected !
I believe that the Template and script is self explanatory but please note that the script passes an instance of the clicked link to the script (onclick="SelectRow(this)") and further when locating the data the use of the 0 index ($(e).closest("tr")[0])
I could not find any reference to this problem and only found the solution through many attempts and breakpoints !
I am sure that there is a better solution, and I would be really grateful if Support would comment and enlighten me !