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

Grid.One("DataBind does not work if mutiple grids in one view.

2 Answers 91 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Kenneth
Top achievements
Rank 1
Kenneth asked on 03 Sep 2013, 08:32 PM
Hi,

I have a view with 4 kendo grids  (Version 2013.1.514 MVC complete) doing different functions for the user and I have a central mechanism to handle all errors from all the grids of the application.

Grid Configuration
@(Html.Kendo().Grid<NewAlta.DataCapture.DataModel.ParameterOverride>()
                   .Name("test")
                   .Columns(columns =>
                       {
                           columns.Bound(p => p.CustomerId).Hidden();
                           columns.ForeignKey(p => p.EquipmentId, (System.Collections.IEnumerable)ViewData["equipments"], "EquipmentId", "Description").Title("Equipment").EditorTemplateName("CustomerEquipmentId");
                           columns.ForeignKey(p => p.ParameterId, (System.Collections.IEnumerable)ViewData["parameters"], "ParameterId", "ParameterName").Title("Parameter").EditorTemplateName("ParameterId");
                           columns.Bound(p => p.Limit1).Width(100);
                           columns.Bound(p => p.Limit2).Width(200);
                           columns.Bound(p => p.Limit3).Width(200);
                           columns.Bound(p => p.Limit4).Width(100);
                           columns.Command(p => p.Edit()).Width(80);
                       })
                   .ToolBar(toolbar => toolbar.Create())
                   .Editable(editable => editable.Mode(GridEditMode.InLine))
                   .AutoBind(false)
                  // .Navigatable(builder => builder.Enabled(true))
                   .Events(events =>
                       {
                           events.Change("test");
                           events.Edit("test");
                           events.Save("test");
                       })
                   .Selectable(builder => builder.Mode(GridSelectionMode.Single))                  
                   .DataSource(dataSource => dataSource
                                                 .Ajax()
                                                 .ServerOperation(false)
                                                 .Events(e => e.Error("errorHandler"))
// omitted for brevity
Error Handler
<script type="text/javascript">
    function errorHandler(e) {
        gridErrorHandler(e, "#test");
    }
 
 
//The below function lies in some js include files.
function gridErrorHandler(args, gridId) {
    if (args.errors) {
        var message = "We have encountered following errors : \n <ul>";
        $.each(args.errors, function (key, value) {
            if ('errors' in value) {
                $.each(value.errors, function () {
                    //alert(this);
                    if (this != "" && this != null)
                        message += "<li>" + this + "</li> \n ";
                });
                message += "</ul>";
            }
        });
        var kgrid = $(gridId).data("kendoGrid");
     
         
        kgrid.one('dataBinding', function (e) { //==> if we have only one grid in the view this works. for mutiple grids in view it does not trigger
            e.preventDefault();   // cancel grid rebind if error occurs 
        });
         
        showAlertWindow(message); //==> Some other function used to show kendo window with errror messages.
        
    }
}
</script>
I could verify that the kgrid is object but databinding event is not triggered in a view with multiple grids.

Any help is highly appreciated!!!

Thanks,

2 Answers, 1 is accepted

Sort by
0
Kenneth
Top achievements
Rank 1
answered on 04 Sep 2013, 11:39 AM
Anyone from the product team?
0
Petur Subev
Telerik team
answered on 05 Sep 2013, 11:13 AM
Hello Kenneth,

The code looks valid and the dataBinding event should be hooked to the Grid that throwed the exception. Can you share a demo project which we can run so we can investigate further?

Kind Regards,
Petur Subev
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
Grid
Asked by
Kenneth
Top achievements
Rank 1
Answers by
Kenneth
Top achievements
Rank 1
Petur Subev
Telerik team
Share this question
or