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

dynamically change autoBind setting

3 Answers 744 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Michael
Top achievements
Rank 2
Iron
Iron
Iron
Michael asked on 03 Sep 2015, 07:38 PM

We have a kendo grid that lists users with roles in our application.  When editing a role we want to bind the kendo combobox editor control using one service method that get's the actual employee record (based on EE #) and bind the combobox to that.  When creating a new role we want to dynamically search for the employee to be granted a role which requires a separate service method to pattern match on partial name typed into combobox and return the matches.  The first scenario works like a charm when autoBind is set to "true" but for the second scenario it is necessary to have the autoBind set to false so it does not try to fire when the datasource is (re)initialized to point to the appropriate service method.  I have this functionality being configured when the "edit" event is fired on the grid and looking to see if I'm dealing with a new model or an existing one to set the datasource as necessary but unfortunately there is no way to set the autoBind to false (via API method) and thus the service method for the "create" functionality is called immediately but errors out because the required filter parameters for the service method are not yet available.  Am I missing something or is there truly no way to dynamically set/change the autoBind value?

 

if (e.model.isNew() == false) {
 
                // get the empid of the current record being edited
                var empID = e.model.get("EmpID");
                // configure $scope.employeeDataSource
                $scope.employeeDataSource =
                    new kendo.data.DataSource({
                        type: "odata-v4",
                        transport: {
                            read:
                                function (e) {
                                    caoService.getEmployeeFromEmpID(empID).then(function (data) {
                                        e.success(data);
                                    })
                                }
                        }
                    })
                // set the datasource and call the read method
                $(e.container).find('[name="EmpID"]').data("kendoComboBox").setDataSource($scope.employeeDataSource);
                $(e.container).find('[name="EmpID"]').data("kendoComboBox").dataSource.read();
 
            } else {
                 
                // configure $scope.employeeDataSource
                $scope.employeeDataSource =
                    new kendo.data.DataSource({
                        type: "odata-v4",
                        serverFiltering: true,
                        transport: {
                            read:
                                function (e) {
                                    caoService.findEmployeesByEmployeeName($scope.selectedSector, $scope.employeeName).then(function (data) { e.success(data); })
                                }
                        }
                    })
                // set the datasource
                $(e.container).find('[name="EmpID"]').data("kendoComboBox").setDataSource($scope.employeeDataSource);
 
            }

3 Answers, 1 is accepted

Sort by
0
Accepted
Kiril Nikolov
Telerik team
answered on 07 Sep 2015, 06:35 AM

Hello Michael,

 

Can you set the autoBind option to false all the time, and call the dataSource.read() method whenever you want to populate the dataSource? This way you will keep the required functionality. Unfortunately the autoBind option cannot be set after the widget has been initialized or changed during run time.

 

Regards,
Kiril Nikolov
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Michael
Top achievements
Rank 2
Iron
Iron
Iron
answered on 08 Sep 2015, 02:43 PM

Kiril,

 It is not the ideal situation but it does appear I can use this as a workaround - the only kicker is having to move focus off of the combobox when doing the employee name search to get the "change" event to fire where I call the read() method - kind of klunky but it works.  Is it impossible for this behavior (dynamic autobind) - don't want to waste my time submitting a change request if it is technologically impossible otherwise I would respectfully request that this be considered as a future enhancement.

 Regards,

Michael J.

0
Kiril Nikolov
Telerik team
answered on 09 Sep 2015, 07:25 AM

Hello Michael,

 

You can either move the change event handler to a separate function, so you do not need to move the focus in order to change event to fire, and you can just call the function. Or you use jQuery trigger() on the widget reference and trigger the change yourself, like this:

 

$("#combobox").getKendoComboBox().trigger("change");

 

I hope this helps!

 

Regards,
Kiril Nikolov
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
Tags
ComboBox
Asked by
Michael
Top achievements
Rank 2
Iron
Iron
Iron
Answers by
Kiril Nikolov
Telerik team
Michael
Top achievements
Rank 2
Iron
Iron
Iron
Share this question
or