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

Events.DataBound not available

11 Answers 315 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Alex
Top achievements
Rank 1
Alex asked on 09 Jun 2015, 08:32 PM

I'm trying to use the databound event with an MVC Kendo Grid, but DataBound is not in the list of options.  I really need a javascript method to fire after the data is rendered to make use of it, and based research, I really can only do it with the databound event.  I'm using version 2015.1.429.340 of the dll, which is the most recent I could find. I have Sync, Push, RequestEnd, many other events available.  Just not DataBound.  

 

My code looks like this:

 

@(Html.Kendo().Grid<type>()
                .Name("name")
                .Columns(columns =>
                {
                    column stuff
                })
                .DataSource(dataSource => dataSource
                    .Ajax()
                            .Read(read => read.Action("method", "controller", new { id = "idstuff" }))
                            .Events(events => events.DataBound("method") )      
                )                
                .ToClientTemplate()

)

 

I hover over the red squiggly on DataBound and I see:

 

Kendo.Mvc.UI.Fluent.DataSourceEventBuilder does not contain a definition for DataBound and no extension method for DataBound accepting the first argument of type 'Kendo.Mvc.UI.Fluent.DataSourceEventBuilder' could be found.

 

Can someone please help me rectify this issue?

 

Thanks!

 

 

11 Answers, 1 is accepted

Sort by
0
Dimiter Madjarov
Telerik team
answered on 10 Jun 2015, 09:08 AM

Hello Alex,

The reason for the issue is that the invoked method is the Events() method of the DataSource, so it will display the dataSource events. In order to attach handlers to Grid events you should invoke the Events() method of the Grid Fluent API.

@(Html.Kendo().Grid<type>()
   .Name("name")
   .Columns(columns =>
   {
       column stuff
   })
   .Events()
   .DataSource(dataSource => dataSource
       .Ajax()

Regards,
Dimiter Madjarov
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Alex
Top achievements
Rank 1
answered on 10 Jun 2015, 09:15 AM

Thanks, that did allow me to use the databound method.  However it did not act as I expected.  The javascript (in this case a simple alert) fired off BEFORE the detail grid was rendered.  I need to call a method AFTER the detail grid is rendered to reference checkboxes in that detail grid.  Is there an event for that?

Thanks again.

0
Alex
Top achievements
Rank 1
answered on 10 Jun 2015, 09:17 AM

Thanks, that did allow me to use the databound method.  Unfortunately it did not act as I expected.  It fired off the method (in this case as simple alert) BEFORE the detail grid was rendered.  This grid is a detail grid for another parent grid.  I need the event to fire AFTER the detail is rendered, is there an event for that?

 Thanks again.

0
Alex
Top achievements
Rank 1
answered on 10 Jun 2015, 09:17 AM
Sorry for double post, site told me there was an error when I posted.
0
Dimiter Madjarov
Telerik team
answered on 10 Jun 2015, 09:38 AM

Hello Alex,

Indeed the dataBound event of the detail Grid is the correct place to reference the checkbox in the rendered table rows. Could you provide small isolated runnable example that I could inspect locally and assist further if needed?

I am looking forward to hearing from you.

Regards,
Dimiter Madjarov
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Alex
Top achievements
Rank 1
answered on 10 Jun 2015, 10:40 AM

Ok Dimiter,  I have a great example project but it's over the 2mb limit.  It's 15mb.  Is there some way I can get that to you since I can't attach it here?

0
Alex
Top achievements
Rank 1
answered on 10 Jun 2015, 10:47 AM

Dimiter, I've attached just the Controller and Views.  You should be able to plug that into a starter kendo mvc project (that's the template I used when I set mine up, but I did have to add a kendo.mvc reference and a lib folder to hold it in).  If I can send you the full solution by other means, let me know how.

 
If you run this, you'll see that if you set a breakpoint in the "Detail" action method, that the databound event, which fires off a method called test() which just has an alert, happens BEFORE the Detail action is even hit.  So obviously it isn't happening after the data is rendered.  


I need to interact with the checkbox that gets rendered after the detail grid is populated, but I didn't need to include that bit of code because the issue is evident just by observing the alert and the breakpoint.


Thanks so much for looking into this!

 

0
Dimiter Madjarov
Telerik team
answered on 10 Jun 2015, 11:01 AM

Hello Alex,

I would not recommend using the alert() method for debugging in this case. Regarding the problem, I was unable to observe it. For example the following code accesses the checkboxes and checks them in the dataBound event handler.
E.g.

function test() {
    this.tbody.find("input[type='checkbox']").prop("checked", true);
}

Regards,
Dimiter Madjarov
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Alex
Top achievements
Rank 1
answered on 10 Jun 2015, 11:16 AM

A few points to make here

 1) Does that code actually run for you?  There is no reference to 'this' that I can see there

 2) Why is alert bad to use?  The method being called could have anything in it.

 3) To test that, I changed it so that instead of alerting, it updates a span html, and I can clearly see that it is updating it before the breakpoint in the detail action.  So it is NOT waiting until the data is returned or rendered to call the javascript method.

0
Dimiter Madjarov
Telerik team
answered on 10 Jun 2015, 12:52 PM

Hello Alex,

I noticed the reason for the issue. Only the name of the event handler function should be passed as a parameter, no parenthesis is required.
E.g.

.Events(e => e.DataBound("test"))

I assume that this is also the reason for the timing issue i.e. executing the function before the actual data binding.

Regards,
Dimiter Madjarov
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Alex
Top achievements
Rank 1
answered on 10 Jun 2015, 01:03 PM
Wow something so simple.  Thank you for figuring this out!
Tags
Grid
Asked by
Alex
Top achievements
Rank 1
Answers by
Dimiter Madjarov
Telerik team
Alex
Top achievements
Rank 1
Share this question
or