2016-07-13 14 views
0

をキャンセル:でMVC Telerikグリッドこれは私Telerikグリッドコードで更新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 { 
     // Here I want to cancel the update request 
     } 
    } 
} 

@(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のを使用して "更新" 機能を中断してい"else"オプションAJAXの "update"リクエストを取り消したい。

可能ですか?

ありがとうございます!

答えて

0

このコード行は、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イベント

The event handler function context (available via the this keyword) will be set to the data source instance.

It is possible to prevent the remote request. To achieve this, execute e.preventDefault() in the handler function.

This event can be prevented only for read requests.

、以下に添付のリンクを参照してくださいするための記述です。

おそらく

http://www.telerik.com/forums/prevent-datasource-read-request-to-server#70iyzKcdAEibUPEpGJL_hw

http://www.telerik.com/forums/cancel-ongoing-ajax-filter-request-and-start-new-one#tQxdD9YFpESlQK_zrVC4jg

ない全く不可能間違いなく、いくつかの余分な作業が必要になります。

+0

すぐにお返事ありがとうございます。 実際には、この行を使って私は次のエラーを受け取りました: "VM466:43未知の型エラー:e.set_enableAjaxは関数ではありません"。 しかし、AJAX関数の実行が停止されました。 – Lena

+0

@Lena Hmm、ok、 'set_cancel(true);'メソッドを試してみることができますか? – woodykiddy

+0

エラー:「未捕捉ReferenceError:set_cancelが定義されていません」 – Lena

関連する問題