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

[Solved] Mvvm databinding on Dropdown for Filter Row of Grid

2 Answers 257 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Lance
Top achievements
Rank 1
Lance asked on 19 Feb 2015, 03:04 AM
Hi,

I am writing a Kendo SPA application that uses MVVM.  I have a Kendo Grid and want to take advantage of the Filter Row capabilities.  I want to set up a couple of the column filters to be dropdownlists that are databound to data from a function in the ViewModel.  I have tried all different combinations and haven't been able to get it to work.  I can create a template function:  
template: function (element)
         {
            return element.element.kendoDropDownList({
                dataSource: ["EquipmentAcquisition", "EquipmentLoan"]
               });
         }
This works only if I list the values of the datasource explicitly as above. If I replace
["EquipmentAcquisition", "EquipmentLoan"]
with the name of the function in the viewmodel that returns an array it doesn't work.  I tried
template: kendo.template($("#Script1").html()) 
    <script id="Script1" type="text/x-kendo-template">
       <div data-role="dropdownlist" data-bind="source: requestTypesSource"></div>
    </script>

but this doesn't work either. 

Please can you help me achieve this?

The kendo version I am using is 2014.3.1119.

Thanks

2 Answers, 1 is accepted

Sort by
0
Petur Subev
Telerik team
answered on 20 Feb 2015, 02:45 PM
Hello Lance,

This cannot be achieved. The filter-row itself is bound through MVVM to a model that on change actually calls the dataSource.filter() method with the corresponding method. And one HTML piece could only be bound to a single model.

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
Lance
Top achievements
Rank 1
answered on 25 Feb 2015, 04:24 AM
Hi Petur,

I've managed to achieve what I wanted and thought I would post in case it helps anyone else and also so you can let me know if you foresee any issues with this approach.

On my html I define my filter columns as such:

                        {"field": "RequestType", "title": "Request Type", "width": "90px", filterable: {
                                cell: {
                                        template: function (element)
                                                  {
                                                      return element.element.kendoDropDownList({
                                                        
                                                      });
                                                  }
                                }}},

and on the Show method of my view I add the following code to bind the filter dropdowns:

            show: function (e)
            {
                var fc = $("[data-role=filtercell][data-field=RequestType]");
 
                var ddl = fc.find("[data-role=dropdownlist]").getKendoDropDownList();
                ddl.dataSource.data(commondatadf.getRequestTypes());
     }
Tags
Grid
Asked by
Lance
Top achievements
Rank 1
Answers by
Petur Subev
Telerik team
Lance
Top achievements
Rank 1
Share this question
or