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

Problem with dataBound event on nested list

5 Answers 107 Views
MVVM
This is a migrated thread and some comments may be shown as answers.
Marcin
Top achievements
Rank 1
Veteran
Marcin asked on 11 Jun 2014, 02:22 PM
Hello

I have viewModel that is created from remote dataSource

var viewModel = window.kendo.observable({
            dataSource: data.dataSource,
            dataBound: function() {
               // do something
            }
});

this view model is bound to list:

<div class="list edit-form"
            data-role="listview"
            data-source="{ 'pageSize': 5 }"
            data-bind="source: dataSource"
            data-auto-bind="false"
            data-template="list-line-template">
       </div>
       <div class="pager k-pager-wrap"
            data-role="pager"
            data-source="{ 'pageSize': 5 }"
            data-bind="source: dataSource"
            data-auto-bind="false">

Inside list there is nested sublist with is bound with:

<div class="form-group-indent" data-bind="source: SubList" data-template="list-subline-template">
               </div>

Everything is working except one thing, I need to run some code after all list is finished loading and finished binding: I tried

events: { dataBound: dataBound }

on list element, but this is fired too soon, before sublist is bound.
When I add the same in place where sublist is bound, the even is not fired, becuase I beleive it si trying to find function inside nested element, not on root.

So my question is how to add event handler to dataBound event from viewModel (parent), or is there any event that is called when everything is bound, all parent and child items to listview?

Regards
Marcin


5 Answers, 1 is accepted

Sort by
0
Petur Subev
Telerik team
answered on 13 Jun 2014, 10:25 AM
Hello Marcin,

I am afraid there is no such event, the parent does not know how many records there are below (how many children there are) and if there are children of the children. I am afraid there is no suitable solution to this case.

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!
 
0
Marcin
Top achievements
Rank 1
Veteran
answered on 13 Jun 2014, 10:32 AM
eh, that's a pity, I think it would be at least usefull to be able to call some global method e.g. assiciated to window. But currently even that is not possible. The best would be to have some parent selector.

Regards
Marcin
0
Petur Subev
Telerik team
answered on 16 Jun 2014, 06:56 AM
Hello Marcin,

On a side note I would like to provide some additional information just for the record. You can use jQuery to select children or parent. For example to get any existing child of a parent Grid you can use the following:

$("#masterGridID").find(".k-grid").each(function(){
    var childGrid = $(this).data("kendoGrid");
      //...
})

However the issue here is that there is not event to know that every child is initialized (because the child Grid are initialized when the expand icon is clicked). 

The opposite traversing (from child to the parent) is also possible.

var parent = $("#someChildGrid23").parent().closest(".k-grid").data("kendoGrid");

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!
 
0
Marcin
Top achievements
Rank 1
Veteran
answered on 16 Jun 2014, 07:05 AM
Thank for your answer, but this is not my issue.

I'm using ListView which have biding to elements that have some subelements. All is bound at the same moment but with different template, like with code example I provided. So the is no expand/collapse. All is displayed at once.

My main problem is that I need an event to know when all bounding operations are finished. To make some custom javascript after everything is already built and displayed.

The databound event on list view source is fired when main elements are bound. And then subelements are bound, and after that I don't have any information that it was finished. I really don't need information when each group of subelements are bound, but just global information when all job is finished and I can start some post initialization process.

Regards
Marcin
0
Petur Subev
Telerik team
answered on 16 Jun 2014, 08:52 AM
Hello again Marcin,

My apologies I got configured by a similar case with the Grid that I am currently working on - sorry for that. As I covered in my previous post there is no such event which we can use to even count how many times that event was triggered and thus calculate if all the children are bound.

Feel free to suggest such idea on our official feedback portal where more people can vote for it:

http://kendoui-feedback.telerik.com/forums/127393-telerik-kendo-ui-feedback

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
MVVM
Asked by
Marcin
Top achievements
Rank 1
Veteran
Answers by
Petur Subev
Telerik team
Marcin
Top achievements
Rank 1
Veteran
Share this question
or