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

Re-read with new URL

3 Answers 92 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Kevin
Top achievements
Rank 1
Kevin asked on 26 Jun 2019, 12:40 AM

Currently I read the data needed for the ComboBox like:

            $(domNode).kendoComboBox({
                dataSource: {
                    transport: {
                        read: function(options) {
                            setReadOptions && setReadOptions(options);
                            const filters = that.getDataSourceData(options.data);
                            const serviceUrl = `${trackUrl.includes('?') ? trackUrl + '&' : trackUrl+'?'}${that.encodeData(filters)}`;
                            ajax.get<any>(serviceUrl)
                                .then((returnObj) => {
                                    let comboBoxOptions = returnObj;
                                    if (filterOptions) {
                                        comboBoxOptions = filterOptions(returnObj);
                                    }
                                    options.success(comboBoxOptions);
                                }).fail(() => {
                                    options.error("Could not retrive data for selected document Id.");
                                })
                        },
                        prefix: ''
                    },
. . . . .

Now there is the possibility of the url that is used could change. Based on that changed url I would like to set new options with a call to something like  I do for when the ajax method returns

                                    if (filterOptions) {
                                        comboBoxOptions = filterOptions(returnObj);
                                    }
                                    options.success(comboBoxOptions);

I know I can refresh the comboBox with something like

                this.comboBox.dataSource.read()

But I don't know how to also affect the options for the comboBox?

 

Kevin

3 Answers, 1 is accepted

Sort by
0
Ivan Danchev
Telerik team
answered on 27 Jun 2019, 02:18 PM
Hello Kevin,

The options of the ComboBox can be set with the setOptions method, which the widgets inherit from the base kendo.ui.Widget class. Here's an example of setting two options (filter and minLength):
var combobox = $(domNode).data("kendoComboBox");
 
combobox.setOptions({
 minLength: 3,
  filter: "contains"
});

Regards,
Ivan Danchev
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Kevin
Top achievements
Rank 1
answered on 27 Jun 2019, 06:32 PM
I am sorry. I don't think I meant options in the Kendo sense. I guess I just wanted to be able to change the drop-down values without reinstantiating the ComboBox. Thank you,
0
Ivan Danchev
Telerik team
answered on 01 Jul 2019, 12:52 PM
Hello Kevin,

Changing the data of the ComboBox after initialization can be done by done by
  1. setting a new dataSource instance
  2. setting the data of the current data source
  3. adding new items/removing the old items with the dataSource API.

See this dojo example, which demonstrates the first two approaches. Setting a new dataSource allows to specify a new url in its configuration. For scenarios that do not require changing the url, for example you are getting the data with an ajax request, it can be passed to the dataSource with its "data" method.

As for adding/removing specific items, instead of replacing all, this can be done with the add and remove API methods.

Regards,
Ivan Danchev
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
ComboBox
Asked by
Kevin
Top achievements
Rank 1
Answers by
Ivan Danchev
Telerik team
Kevin
Top achievements
Rank 1
Share this question
or