这是我的Telerik网格代码:
@(Html.Telerik().Grid(Model).Name("DistributionGrid").DataKeys(dataKeys => dataKeys.Add("DistributionID")).
ToolBar(toolBar => toolBar
.Template(@<text>
@{
<b>Distribution</b>
<ul class='ul-bulk-menu'>
<li><button id='newDistribution' class='t-button t-button-icon' title='New Distribution'><span>Add Distribution</span></button></li>
</ul>
}
</text>))
.Columns(c =>
{
c.Command(command =>
{
command.Edit().ButtonType(GridButtonType.Image).HtmlAttributes(new { title = "Edit Distribution"});
command.Delete().ButtonType(GridButtonType.Image).HtmlAttributes(new { title = "Delete Distribution" });
}).Width(100);
c.Bound(o => o.DistTo);
c.Bound(o => o.DistCC);
})
.Scrollable(o => o.Height(440))
.Resizable(o => o.Columns(true))
.Reorderable(o => o.Columns(true))
.DataBinding(o => o.Ajax()
.Select("SelectDist", "Mail")
.Update("UpdateDist", "Mail")
.Delete("DeleteDist", "Mail")
)
.Editable(editing => editing.Mode(GridEditMode.InForm))
.ClientEvents(events => events.OnCommand("Grid_OnRequestStart"))
)
</div>我有一个使用jQuery的jQuery中断了"update“函数,代码如下:
function Grid_OnRequestStart(e) {
if (e.name == "update") {
alert(e.dataItem.DistTo + " - " + $("#DistTo").val());
if (confirm("Are you sure?")) {
alert("Distribution was updated!");
}
else {
// Here I want to cancel the update request
}
}
}在"else“选项中,我想取消AJAX的"update”请求。
有可能吗?
谢谢你的回答!
发布于 2016-07-13 17:29:30
请尝试此行代码,该行代码将取消ajax请求。
function Grid_OnRequestStart(e) {
if (e.name == "update") {
alert(e.dataItem.DistTo + " - " + $("#DistTo").val());
if (confirm("Are you sure?")) {
alert("Distribution was updated!");
}
else {
e.set_enableAjax(false); // cancel ajax request
}
}
}更新:根据Telerik文档,这里是对requestStart事件的描述
此事件处理程序函数上下文(通过
关键字可用)将设置为数据源实例。
可以阻止远程请求。为此,请在处理程序函数中执行e.preventDefault()。
只能针对read请求阻止此事件。
在论坛的其他帖子中也提到了这一点,请参阅下面的附加链接。
http://www.telerik.com/forums/prevent-datasource-read-request-to-server#70iyzKcdAEibUPEpGJL_hw
也许不是完全不可能,但肯定需要一些额外的工作。
https://stackoverflow.com/questions/38347484
复制相似问题