This is a migrated thread and some comments may be shown as answers.
Batch Editing: Cancel button not working
1 Answer 16 Views
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Matthew
Top achievements
Rank 1
Matthew asked on 24 Apr 2013, 01:56 AM
Hello,  I've implemented this example - batch editing - and it works great with one exception...The cancel button for me doesn't work - it doesn't eliminate the unsaved changes and present me with a fresh grid.  It seems that nothing happens at all.  I believe I've implemented the grid properly.  Do you have any advice?  Thanks


@(Html.Telerik().Grid(Model)
            .Name("Grid")
            .DataKeys(d => d.Add<int>(a => a.Id).RouteKey("Id"))
            .Columns(columns =>
            {
                columns.Bound<int>(c => c.Id).Width(100).ReadOnly();
                columns.Bound<string>(c => c.FirstName).Width(120);
                columns.Bound<string>(c => c.LastName).Width(200);
                columns.Bound<string>(c => c.Phone).Width(120);
                columns.Bound<string>(c => c.Street).Width(200);
                columns.Bound<string>(c => c.City).Width(100);
                columns.Bound<string>(c => c.Province).Width(75);
                columns.Bound<string>(c => c.PostalCode).Width(100);
                columns.Bound<string>(c => c.Email).Width(100);
                columns.Bound<bool>(c => c.OkToContact).Width(50)
                    .ClientTemplate("<input type='checkbox' disabled='disabled' name='OkToContact' <#=OkToContact? checked='checked' : '' #> />");
 
                columns.Command(commands =>
                {
                    commands.Delete();
                }).Width(200);
             
            })
            .DataBinding(dataBinding => dataBinding
            .Ajax()
                .Select("_SelectBatchEditing", "Home")
                .Update("_SaveBatchEditing", "Home")
            )
 
            .ToolBar(commands => {
            commands.Insert();
            commands.SubmitChanges();
            })
 
            .Sortable()
            .Pageable()
            .Scrollable(scrolling => scrolling.Height(494)).Footer(false)
            .Editable(editing => editing.Mode(GridEditMode.InCell))
            .Editable(editing => editing.Mode(GridEditMode.InCell).DefaultDataItem(new ContactView
            {
                OkToContact = true
            }))
            .ClientEvents(events =>
            events.OnDataBinding("Grid_onDataBinding").OnError("Grid_onError").OnSubmitChanges("Grid_onSubmitChanges"))
         )
 
<script type="text/javascript">
 
    function Grid_onSubmitChanges(e) {
        e.values.FirstName = $("#FirstName").val();
        e.values.LastName = $("#LastName").val();
    }
 
 
    function Grid_onError(args) {
        if (args.textStatus == "modelstateerror" && args.modelState) {
            var message = "Errors:\n";
            $.each(args.modelState, function (key, value) {
                if ('errors' in value) {
                    $.each(value.errors, function() {
                        message += this + "\n";
                    });
                }
            });
            args.preventDefault();
            alert(message);
        }
    }
    function Grid_onDataBinding(e) {
        var grid = $(this).data('tGrid');
        if (grid.hasChanges()) {
            if (!confirm('You are going to lose any unsaved changes. Are you sure?')) {
                e.preventDefault();
            }
        }
    }
</script>

1 Answer, 1 is accepted

Sort by
0
Ricardo
Top achievements
Rank 2
answered on 02 May 2013, 11:54 AM
Hi Matthew,

I don't think that this is the problem, but why are you setting the GridEditMode twice?
    .Editable(editing => editing.Mode(GridEditMode.InCell))
            .Editable(editing => editing.Mode(GridEditMode.InCell).DefaultDataItem(new ContactView
            {
                OkToContact = true
            }))


Tags
Grid
Asked by
Matthew
Top achievements
Rank 1
Answers by
Ricardo
Top achievements
Rank 2
Share this question
or