We are creating an MVC 4 application using the Kendo.Mvc helper assembly. The code is working well; however, we appear to be missing something when we try to obtain a reference to a kendo control.
Example:
Our application has an ActionLink on a toolbar. When the user clicks on the ActionLink, we call into a JS function to validate if the displayed grid has a row selected. Within the function we attempt to obtain a reference to the grid and get the selected row. Unfortunately, the select() function throws an error ("Value is undefined").
I have included the code below. Most of our logic will be based on controls having the ability to communicate with each other from events, etc. Are we able to receive the functionality using the MVC assembly, or are we only able to use the API when code in JS?
Any comments or assistance would be much appreciated.
Thanks,
Todd
@(Html.Kendo().Grid(Model.Transaction)
.Name("grid")
.Columns(columns => {
columns.Bound(o => o.EntityId)
.Hidden().Visible(false);
columns.Bound(o => o.EntityName)
.Sortable(true)
.Title("Entity Name")
.ClientTemplate(@Html.ActionLink("#=EntityName#", "Details", "Entity", new { id = "entityId" }, null).ToHtmlString().Replace("entityId", "#=EntityId#"));
columns.Bound(o => o.TransactionType);
columns.Bound(o => o.Name)
.ClientTemplate(@Html.ActionLink("#=Name#", "Details", "Engagement", new { id = "engId" }, null).ToHtmlString().Replace("engId", "#=ID#"));
columns.Bound(o => o.TransactionStatus);
columns.Bound(o => o.Initiator);
columns.Bound(o => o.Reason);
})
.Pageable(p => p.PageSizes(true))
.Filterable(filterable => filterable
.Extra(false)
.Operators(operators => operators
.ForString(str => str.Clear()
.StartsWith("Starts with")
.IsEqualTo("Is equal to")
.IsNotEqualTo("Is not equal to")
))
)
.Navigatable()
.Resizable(resize => resize.Columns(true))
.Selectable()
.DataSource(dataSource => dataSource
.Ajax()
.Model(model => model.Id(p => p.ID))
.Read(r => r.Action("Search", "Transaction")))
)
getSelectedRowId:
function
(gridId) {
var
grid = jQuery(gridId).kendoGrid().data(
"kendoGrid"
);
var
row = grid.select();
if
(row.length > 0)
return
grid.dataItem(row).id;
else
return
null
;
}