开发者

Telerik MVC Grid Delete operation

i would like t开发者_开发问答o ask how i can intercept the ajax delete functionality of a grid using ajax binding? specifically, up to the point wherein, after i click on delete, as the confirm prompt pops up, i would like to do something based on the user's choice,

basically, if OK, do this, if CANCEL do that..


You need to use the OnRowDataBound and attach a click handler to the delete button. Then you can display custom confirmation and decide what to do. If you want' to prevent the grid deletion code - call e.stopPropagation(). Here is a quick sample:

<%: Html.Telerik().Grid(Model)
        // Prevent the grid from displaying the default delete confirmation
        .Editable(editing => editing.DisplayDeleteConfirmation(false))
        // Subscribe to the OnRowDataBound event
        .ClientEvents(e => e.OnRowDataBound("onRowDataBound"))
%>
<script>
function onRowDataBound(e) {
   $(e.row) // get the current table row (TR) as a jQuery object
      .find(".t-grid-delete") // find the delete button in that row
      .click(function(e) {  // handle its "click" event
          if (confirm("Do you want to delete this record?")) {
             // User clicked "OK"
          } else {
             // User clicked "Cancel"
             e.stopPropagation(); // prevent the grid deletion code from executing.
          }
      });
}
</script>


The demo page seems to contain an example of what you are looking for.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜