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

Bind select element to DataSource view function then apply filter

1 Answer 120 Views
MVVM
This is a migrated thread and some comments may be shown as answers.
Justin
Top achievements
Rank 1
Justin asked on 16 Jan 2013, 08:06 PM
I am trying to bind the view() function on the DataSource to a select element then apply a filter to restrict the results however it is not working.

My expected result in the demo is that by changing the Package to "Application" the Module values would change.
http://jsfiddle.net/v6PBz/3/

Thanks, Justin

1 Answer, 1 is accepted

Sort by
0
Alexander Valchev
Telerik team
answered on 18 Jan 2013, 02:21 PM
Hi Justin,

There are few issues with the current implementation:
  • kendo MVVM bindings are not JavaScript. The following code is not supposed to work:
    data-bind="source: dsPackageInfo.view()"

    Instead please define a function that returns the View:
    filterModel.dsPackageInfoView = function() {
      var view = this.get("dsPackageInfo").view();
      return view;
    }
  • Changing of the DataSource will not 'bubble' to the View-Model. The solution is to bind to the change event of the DataSource and notify manually the View-Model that the DataSource was filtered.
    filterModel.dsPackageInfo.bind("change", function() {
      filterModel.trigger("change", { field: "dsPackageInfo" })
    });
I hope this will help. For convenience I updated your example: http://jsfiddle.net/valchev/v6PBz/11/

Regards,
Alexander Valchev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
MVVM
Asked by
Justin
Top achievements
Rank 1
Answers by
Alexander Valchev
Telerik team
Share this question
or