dynamically change autoBind setting

4 posts, 1 answers
  1. Michael
    Michael avatar
    27 posts
    Member since:
    May 2011

    Posted 03 Sep 2015 Link to this post

    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);
     
                }

  2. Answer
    Kiril Nikolov
    Admin
    Kiril Nikolov avatar
    2565 posts

    Posted 07 Sep 2015 Link to this post

    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!
     
  3. Kendo UI is VS 2017 Ready
  4. Michael
    Michael avatar
    27 posts
    Member since:
    May 2011

    Posted 08 Sep 2015 in reply to Kiril Nikolov Link to this post

    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.

  5. Kiril Nikolov
    Admin
    Kiril Nikolov avatar
    2565 posts

    Posted 09 Sep 2015 Link to this post

    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!
     
Back to Top
Kendo UI is VS 2017 Ready