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

Bind events in the grid row and details view

8 Answers 387 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Yoni
Top achievements
Rank 1
Yoni asked on 02 Jun 2013, 03:09 AM
I need to bind some events on the grid row and details view. I'm using an observable view model with some events registered and trying to bind them to the DOM using row template and details templates. So far no progress.  Here is the jsFiddle http://jsfiddle.net/amGmr/9/  . Is there any possibility to bind events withing the grid using MVVM ?

8 Answers, 1 is accepted

Sort by
0
Rosen
Telerik team
answered on 05 Jun 2013, 05:59 AM
Hi Yoni,

As you may know the binding options are set via attributes, thus the correct syntax is data-bind="some configuration". However, in your case instead of the equal sign a colon is used.

Regards,
Rosen
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Yoni
Top achievements
Rank 1
answered on 05 Jun 2013, 06:31 AM
Hi Rosen,

Ah.. Thanks. My mistake. I have updated it now but if you can see it  again (http://jsfiddle.net/amGmr/12/) , it not binding events to details view. It just only binding event for the data row.

Thanks,
Yoni
0
Rosen
Telerik team
answered on 05 Jun 2013, 07:04 AM
Hi Yoni,

Indeed, the MVVM bindings within the Detail template will not be automatically bound as the detail row actually does not exist in when the binding is executed. Therefore, you should manually bind those items from within the Grid's detailinit event. For example:

detailInit: function(e) {
    kendo.bind(e.detailRow, model);
}

Regards,
Rosen
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Yoni
Top achievements
Rank 1
answered on 05 Jun 2013, 07:48 AM
Hi Rosen,

Ah got it  , Thanks !
0
Yoni
Top achievements
Rank 1
answered on 06 Jun 2013, 03:29 AM
Still my question is why i need to bind the view model twice.  Because the data available to bind to the details template , then why not the events?
0
Rosen
Telerik team
answered on 06 Jun 2013, 07:24 AM
Hello Yoni,

It is required to use the object which the custom handler is member of, due to the way parent relations are resolved. When the kendo.bind is used the provided model is set as top most parent. Therefore,  in your case the event handlers will not be resolved correctly if bound to the child object.

Regards,
Rosen
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Yoni
Top achievements
Rank 1
answered on 14 Jun 2013, 04:41 PM
I have updated to use the detail init event now. But still I'm failing to get the clicked row data item from the event if I bind details template to the parent model. And if I bind this to  the main model I cant't get the relevant child item from the grid. http://jsfiddle.net/amGmr/25/
0
Rosen
Telerik team
answered on 17 Jun 2013, 05:51 AM
Hi Yoni,

As I have already mentioned, in your scenario, in order to bind the handler, the row should be bound to the function's owner. Therefore, when the detail template is bound  to the child object the handler will not be resolved. In this case you should manually hook the handler instead using the MVVM to attach it.

Regards,
Rosen
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
Yoni
Top achievements
Rank 1
Answers by
Rosen
Telerik team
Yoni
Top achievements
Rank 1
Share this question
or