Binding ListView items with MVVM and dataBound event

5 posts, 0 answers
  1. Jaap
    Jaap avatar
    96 posts
    Member since:
    Oct 2012

    Posted 03 Sep 2012 Link to this post

    Hello,



    I use MVVM to bind a ListView to my viewmodel and also the item template uses the MVVM pattern. The ListView dataBound event is binded to a function on my viewmodel.

    The problem is that, when my dataBound function is called, the items exists, but are not yet binded to the data.

    It appears that the item binding is triggered in the ListView.refresh function by calling the trigger('dataBound') function. There are actually 2 dataBound events, my event and an event of the binding system. And it appears my event is called first.

    In my opinion it should be ensured that the binding event is always the first one executing.



    I can workaround it by attaching my dataBound event after the binding of the ListView ( with listview.bind('dataBound', function (e) {...}) ), but that is against the MVVM pattern.



    Regards, Jaap

  2. Alex Gyoshev
    Admin
    Alex Gyoshev avatar
    2500 posts

    Posted 06 Sep 2012 Link to this post

    Hello Jaap,

    We tried reproducing the behavior you described in the following jsBin, to no avail. If this is not your scenario, please elaborate by modifying the example and showing the issue at hand.

    Regards,

    Alex Gyoshev
    the Telerik team
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  3. Kendo UI is VS 2017 Ready
  4. Jaap
    Jaap avatar
    96 posts
    Member since:
    Oct 2012

    Posted 06 Sep 2012 Link to this post

    The template must use MVVM style binding.

    Change the h3 tag to this: <h3 data-bind="text:ProductName"></h3>

    Then you will see that the console.log writes a 'undefined'.



    Regards, Jaap
  5. Alex Gyoshev
    Admin
    Alex Gyoshev avatar
    2500 posts

    Posted 10 Sep 2012 Link to this post

    Hello Jaap,

    Using the template output (rather than binding the text through MVVM is much faster, so this would only make sense for computed values. This is not supported at the present time. Feel free to open a feature request on uservoice.

    Kind regards,
    Alex Gyoshev
    the Telerik team
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  6. Jaap
    Jaap avatar
    96 posts
    Member since:
    Oct 2012

    Posted 10 Sep 2012 Link to this post

    Ok, speed is a valid reason.

    Currently I use in ASP.NET MVC the DisplayTemplates (per property type) for my controls in regular pages and I wanted to reuse them also for my templates.

    Looks like I need to create 2 versions of my display template, one for using with databinding and one for templating.

    Perhaps I can use one template with some switch in it.



    Regards, Jaap
Back to Top
Kendo UI is VS 2017 Ready