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

3 posts, 0 answers
  1. Kenneth
    Kenneth avatar
    5 posts
    Member since:
    Jul 2013

    Posted 03 Sep 2013 Link to this post

    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. Kenneth
    Kenneth avatar
    5 posts
    Member since:
    Jul 2013

    Posted 04 Sep 2013 Link to this post

    Anyone from the product team?
  3. Petur Subev
    Admin
    Petur Subev avatar
    1882 posts

    Posted 05 Sep 2013 Link to this post

    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!
Back to Top