This is a migrated thread and some comments may be shown as answers.

[Solved] How to get cancel button event?

3 Answers 178 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Brian
Top achievements
Rank 1
Brian asked on 11 Apr 2011, 06:17 AM
Wen click "Add new record" button in grid, there have two button ("Insert","cancel"),
How can i get "cancel" button event?
I want to write some bussiness rule!

<%= Html.Telerik().Grid<MvcPoExpense.Models.SmpPoLinesVMeta>()
    .Name("Grid")
    .DataKeys(keys => keys.Add(c => c.LineId))
    .ToolBar(commands => commands.Insert().ButtonType(GridButtonType.Text)
        .ImageHtmlAttributes(new { style = "margin-left:0" }))
    .DataBinding(dataBinding => 
    {
        dataBinding.Ajax()
            .Select("_SelectAjax", "MvcPoExpense", new { hdid = Model.HeaderId })
            .Insert("_InsertAjax", "MvcPoExpense")
            .Update("_Updatejax", "MvcPoExpense", new { hdid = Model.HeaderId })
            .Delete("_DeleteAjax", "MvcPoExpense", new { hdid = Model.HeaderId }); 
    })        
    .Columns(columns =>
    {
        columns.Command(commands =>
        {   
            commands.Edit().ButtonType(GridButtonType.Text);
            commands.Delete().ButtonType(GridButtonType.Text);
        }).Width(180).Title("Commands");
        columns.Bound(o => o.LineNum).Format("{0:G}").Width(60).ReadOnly();
        columns.Bound(o => o.LineTypeName).Width(110);
        columns.Bound(o => o.ItemCategoryName).Width(180);
        columns.Bound(o => o.ItemDesc).Width(140);
        columns.Bound(o => o.NeedByDate).Width(100).Format("{0:yyyy/MM/dd}");
        columns.Bound(o => o.Amount).Width(100).Format("{0:C}");
        columns.Bound(o => o.Requestor).Width(180);
        columns.Bound(o => o.ShipOrganizationCode).Width(100);
        columns.Bound(o => o.AccountSegment4Desc).Width(110);                                    
        columns.Bound(o => o.TaxName).Width(110);
    })
    .ClientEvents(events => events.OnEdit("onEdit"))
    .ClientEvents(events => events.OnSave("onSave"))       
    .Pageable()
    .Editable(editing => editing.Mode(GridEditMode.InLine))
    .Sortable()
    .Scrollable(scrolling => scrolling.Height(300))
%>

3 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 11 Apr 2011, 08:34 AM
Hello Ted, 

Currently there is no built-in event for handling the cancel button click. Fortunately it is easy to implement a workaround using jQuery:

  1. Subscribe to the OnEdit event
  2. Subscribe to the click event of the cancel button:
    <script type="text/javascript">
    function onEdit(e) {
        $(e.form).find(".t-grid-cancel").click(function() {
            alert("cancel");
        });
    }
    </script>

Regards, Atanas Korchev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Jackey
Top achievements
Rank 1
answered on 17 Nov 2011, 09:40 PM
Upper one is working but name of cancel changes will differ, so with new extensions this is the name of dynamic control which i mentioned.

    
function
 onEdit(e) {     //attaching event with cancel changes control     $(".t-grid-cancel-changes").click(function () {}

}
0
jfkrueger
Top achievements
Rank 1
answered on 15 Jun 2012, 05:09 PM
How would I call a controller action from this method? I have tried the following but the method never gets called:

$(e.form).find(".t-grid-cancel").click(function () {
 
    var actionUrl = "/CatalogAdministration/RemoveBlankInventoryItem?inventoryItemId=" + key;
    alert(actionUrl);
    $.post(actionUrl);
 
});

Thanks!




Tags
Grid
Asked by
Brian
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Jackey
Top achievements
Rank 1
jfkrueger
Top achievements
Rank 1
Share this question
or