How to update Multiselect data?

0 Answers 151 Views
Data Source General Discussions MultiSelect
Vsevolod
Top achievements
Rank 1
Iron
Iron
Vsevolod asked on 10 Sep 2024, 11:56 AM

Hi!

I initialized a multiselect:


 let kendoMultiSelect = $("#multisel").kendoMultiSelect({
     dataSource: ['item1'],
     value: ['item1'],
     autoClose: false
 }).data("kendoMultiSelect");

 

and function of refresh multiselect data:


$.ajax({
     url: myUrl,
     type: "POST",
     data: window.kendo.stringify({ objId: that.objId }),
     contentType: "application/json",
     cache: false,
     async: true,
     success: function (response) { //response - array (for example: ['new1', 'new2', ...])
         let widget =  $("#multisel").getKendoMultiSelect();
         widget.dataSource = response;
         widget.value = response; //I need all the data to be selected at once
     }
 });

After success query the multiselect did not update.

When I try to open the multiselect dropdown I get an error: "TypeError: this.dataSource.flatView is not a function"

How can I update the multiselect.

Neli
Telerik team
commented on 13 Sep 2024, 09:07 AM

Hi Vsevolod, 

You could use the setDataSource method to set the new DataSource to the component:

- https://docs.telerik.com/kendo-ui/api/javascript/ui/multiselect/methods/setdatasource

  success: function (response) { 
          console.log(response)
          let widget =  $("#multisel").getKendoMultiSelect();
          widget.setDataSource(response)
          widget.value(response[5].ProductID)
}

Here is such Dojo example - https://dojo.telerik.com/@NeliK/uVALAxiz.

Note, that you could also initialize the MultiSelect component and call the ajax request in the transport.read function as demonstrated in the third example in the link below:

- https://docs.telerik.com/kendo-ui/api/javascript/data/datasource/configuration/transport.read

Regards,

Neli

No answers yet. Maybe you can help?

Tags
Data Source General Discussions MultiSelect
Asked by
Vsevolod
Top achievements
Rank 1
Iron
Iron
Share this question
or