剑道格变化事件触发每行选择只有一次 [英] Kendo grid change event fires only once per row selection
本文介绍了剑道格变化事件触发每行选择只有一次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在一个MVC4项目中,我有一个网格剑道时将触发选择的一行的事件。
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>
所以,当我选择了行,则的onChange
函数被调用:
function onChange() {
var code = this.dataItem(this.select()).StretchCode;
$.get('@Url.Content("getStretchCode")',
{ "code": code });
}
在我的控制器中,code被检索和一些操作用它做。
In my controller, the code is retrieved and some operations are done with it.
public void getStretchCode(string code)
{
currentStretch.RoadComponentCode = code;
...
}
这工作正常。问题是,该事件被解雇每次我选择一个不同的行,但如果我选择一排,这是pviously选择$ P $,不触发事件时间,我不能让该行的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.
任何帮助吗?
推荐答案
添加 .Selectable()
在网格所以它允许您选择previously一行。
Add .Selectable()
in your grid so it allow you select previously row.
@(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);
...
})
.Selectable(selectable => selectable
.Type(GridSelectionType.Row) <--------- Add This
)
.Events(e => e.Change("onChange"))
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(15)
.Read(read => read.Action("GetStretches", "MasterData"))
)
)
脚本
function onChange() {
var code = this.dataItem(this.select()).StretchCode;
$.post('@Url.Content("getStretchCode")',
{ "code": code });
}
这篇关于剑道格变化事件触发每行选择只有一次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文