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

Binding multiple Events for a Grid with the => notation

2 Answers 789 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Thomas Sonnenschein
Top achievements
Rank 2
Thomas Sonnenschein asked on 07 Feb 2013, 03:38 PM
Hello Community,

  I have a syntax problem, which even with extensive internet search, I found no solution.

I want to create a grid with a function bound to the "DataBound" and the "DataBinding" event.

My Syntax is like this (incomplete snippet here, but correct:working)
@(Html.Kendo ().Grid<mvcEw.Models.WeldersModel> (Model)
                                        .Name ("MasterGrid")
                                        .Events (events => events.DataBound ("gridDataBound"))
                                        .HtmlAttributes (new { style = "height:100%;" })
...

But this binds only the "DataBound" Event. How can I add here additionally the "DataBinding" Event? An additional row like
       .Events (events => events.DataBinding ("gridDataBinding"))
direct under the first .Event row gives syntax and runtime error. I'm stuck here.

All Samples in the net bind only one event like this and I don`t want to bind afterwords via JavaScript. All declaration should be together for this grid.

In hope for help
  Thomas

2 Answers, 1 is accepted

Sort by
0
Thomas Sonnenschein
Top achievements
Rank 2
answered on 08 Feb 2013, 11:38 AM
Hello again,

  I think, I found the problem. The syntax (which I found after another some hours of searching and then found a sample to a complete other theme) was in fact correct, But the Event "DataBinding" which is here described, cannot be used in the HTML helper.The underlying "GridEventBuilder" Class has no member "DataBinding". So the documentation I think is wrong.

Even in the GridBuilder Documentation (nearly at the end of the Page in the section "Events" there is code for binding to the "DataBinding", which is not working in Kendo UI for ASP.NET MVC Q3 2012 (2012.3.1315).

So the question now is, how to bind the "DataBinding" or a similar event to my grid?

Greetings
  Thomas
0
Vladimir Iliev
Telerik team
answered on 11 Feb 2013, 12:46 PM
Hi Thomas,

 
Basically the DataBinding event currently is not exposed in the Grid HTML helper, however you can bind it on document ready - please check the example below:

@(Html.Kendo().Grid<Kendo.Mvc.Examples.Models.ProductViewModel>()
    .Name("Grid")
    .Columns(columns =>
    {
        columns.Bound(p => p.ProductID).Groupable(false).Width(140);
        columns.Bound(p => p.ProductName);
    })
    .Pageable()
    .Events(e => e.DataBound("onDataBound"))
    .DataSource(dataSource => dataSource
        .Ajax()
        .Read(read => read.Action("Products_Read", "Grid"))
     )
)
 
<script>   
    function onDataBound(e) {
        //DataBound event handler code
    }
 
    $(function () {
        var grid = $("#Grid").data("kendoGrid");
        grid.bind("dataBinding", function () {
            //DataBinding event handler code
            debugger;
        });
    })
</script>

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