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

Initial Value When bound to Remote Data

2 Answers 198 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Jeremy
Top achievements
Rank 1
Jeremy asked on 01 Apr 2015, 06:04 PM
Using pure jQuery, I have a ComboBox that retrieves values from a webservice.  How do I set the initial value such that it shows the name, and not the ID?

For example I have 1 million customers in my database, but on page load I want to show that customer #17, Bob's Burgers, is currently selected.

I'd like the combobox to initially show  [Bob's Burgers] and have a value of 17.

Thanks in advance!


var a = $(item).kendoComboBox({
       placeholder: "Select",
       dataTextField: "Name",
       dataValueField: "id",
       filter: "contains",
       autoBind: false,
       width: "400px",
       dataSource: {
           type: "json",
           serverFiltering: true,
           transport: {
               read: {
                   type: 'POST',
                   url: "../WebServices/DropdownWebService.asmx/SearchCompanies",
                   item: item,
                   contentType: 'application/json; charset=utf-8',
                   datatype: 'json',
                   data: function (result) {
                       return {
                           ssid: globalValues.ssid,
                           query: result.filter?result.filter.filters[0]?result.filter.filters[0].value:"":"",
                           type: $(this.item).attr('data-type')
                       }
                   }
               },
               parameterMap: function (options) {
                   return JSON.stringify(options);
               }
           },
           schema: {
               data: "d"
           } // schema
       },
       template: '<span class="col-first"><span class="type-box-#: data.EntityType#">#: data.Name#</span></span>'
   });

2 Answers, 1 is accepted

Sort by
0
Plamen
Telerik team
answered on 03 Apr 2015, 07:57 AM
Hi Jeremy,

Thank you for contacting Telerik support.

You can use the DataBound event and the select method to select the desired item as in this example - http://dojo.telerik.com/@zdravkov/AMuDE.

Regards,
Plamen
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Jeremy
Top achievements
Rank 1
answered on 03 Apr 2015, 04:49 PM

That looks to be exactly what I need. Thanks!

 

 

Tags
ComboBox
Asked by
Jeremy
Top achievements
Rank 1
Answers by
Plamen
Telerik team
Jeremy
Top achievements
Rank 1
Share this question
or