In a MVC4 project, I've got a kendo grid that fires an event when a row is selected.
<div id="datagrid">
@(Html.Kendo().Grid<SustIMS.Models.StretchModel>()
.Name("datagrid_Stretches")
.Columns(columns =>
{
columns.Bound(s => s.StretchCode).Title(ViewBag.lblCode).Width(80);
columns.Bound(s => s.StretchMediumDescription).Title(ViewBag.lblDescription);
...
})
.Events(e => e.Change("onChange")) <--------- here's the event
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(15)
.Read(read => read.Action("GetStretches", "MasterData"))
)
)
</div>
So, when I select a row, the onChange
function is called:
function onChange() {
var code = this.dataItem(this.select()).StretchCode;
$.get('@Url.Content("getStretchCode")',
{ "code": code });
}
In my controller, the code is retrieved and some operations are done with it.
public void getStretchCode(string code)
{
currentStretch.RoadComponentCode = code;
...
}
This works fine. The problem is, the event is fired every time I select a different row but if I select a row that was previously selected, the event isn't fired and I can't get the code of that row.
Any help?
Add
.Selectable()
in your grid so it allow you select previously row.Script
you should add Selectable() before add event like this