Does KendoMultiSelect provide option to call a function during multiselect initialization?

1 Answer 14 Views
MultiSelect
Anuj
Top achievements
Rank 1
Anuj asked on 12 Jan 2023, 08:36 PM

I am trying to move away from using select2 multi-select. Ideally, I would like to call a function that returns the value for the kendo multi-select during initialization. The value will be retrieved by an AJAX call. Is there any way I could implement this? I tried using dataBound, but it looks like anything inside the data-bound will be called every time user clicks on the multi-select control. 

During initialization, I don't want to call the dataSource. This will be updated every time user clicks open. I just need to update the value field based on the AJAX result.
$("#multiselect").kendoMultiSelect({
  dataSource: {
    transport: {
      read: {
        url: "https://demos.telerik.com/kendo-ui/service/products",
        dataType: "jsonp"
      }
    }
  },
  open: function(e){
    // datasource is dynamic and should be updated with every click.
    $('#multiselect').data('kendoMultiSelect').dataSource.read();
  },
  dataTextField: "ProductName",
  dataValueField: "ProductID",
  autoBind: false,
  value: "IS IT POSSIBLE TO GET DATA FROM AJAX DURING INITIALIZATION?"
});
Is this possible with telerik multiselect?

1 Answer, 1 is accepted

Sort by
0
Martin
Telerik team
answered on 17 Jan 2023, 11:19 AM

Hello, Anuj,

If the dataBound event would work for you, you can have a boolean (e.g. isValueSet = false ) and on the first DataBound event trigger you can get the value for the MultiSelect using AJAX call, set it to the component and then set the isValueSet to true. That would ensure that this specific code block would occur only once.

dataBound:function(e){
     if(isValueSet === false){
         isValueSet = true;
         // do AJAX call
         // set MultiSelect value    
     }
}

Let me know if that would be acceptable for you.

Regards,
Martin
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
MultiSelect
Asked by
Anuj
Top achievements
Rank 1
Answers by
Martin
Telerik team
Share this question
or