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

Set initial value if serverfiltering is true

3 Answers 241 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Jens
Top achievements
Rank 1
Jens asked on 14 Nov 2017, 09:14 AM

Hello,

how can I set an initial value if the control has serverfiltering is true?

http://demos.telerik.com/aspnet-mvc/combobox/serverfiltering

To be clearer we have a multipage wizard where you can navigate between his pages. On the first page we have some comboboxes with a large datasoure (200k~ items). So we set the combobox to filter on server which works well. We got the entered text and fire a contains query against the database. If the user now submits the form with the combobox in it, we store the key value (15) in die session. After a while the user decides to choose an other value from that combobox and opens the page of it. Now we want to show the previous selected value in that combobox, but how? We have first tried to set its value via javascript .value(15) but that shows the 15 in the combobox but not the text (Tofu). How can we force to select the data from the server if it is not loaded? With .text("Tofu") it shows the tofu but has no key value :( thats maybe because we have multiple items with name Tofu but with diffrent ids.

Thank you!

3 Answers, 1 is accepted

Sort by
0
Dimitar
Telerik team
answered on 16 Nov 2017, 07:15 AM
Hello Jens,

I have provided an answer in the support ticket on the same topic. I would suggest to continue our communication there in order to prevent thread duplication.

Regards,
Dimitar
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Raditya
Top achievements
Rank 1
answered on 30 Nov 2017, 03:55 AM

Hi,

I have a similar problem with Jens. Can you kindly share the solution?

Thanks

Best regards,

Raditya

0
Ivan Danchev
Telerik team
answered on 01 Dec 2017, 04:28 PM
Hello Raditya,

I will copy/paste my colleague Dimitar's post and attach the sample project he has attached in the respective support thread:



Your approach to setting the initial value in the ComboBox with ServerFiltering(true) and AutoBind(false) is correct. Basically, you should be able to properly set the value by using the ComboBox's value() method. Important to note is that this method will pre-fetch the data before setting the value If the widget is not bound (AutoBind(false)). This method also does not trigger change event and this has to be performed manually:
<script>
  var combo = $("#NewsID").getKendoComboBox();
  
  combo.value(id);
  combo.trigger("change");
</script>

Also, the above method will set the selected value according to the DataValueField. The problem in your current scenario is that the DataValueField needs to be unique(not the Name property) in order for the correct dataItem to be selected:
.DataTextField("Name")
.DataValueField("ID")



Regards,
Ivan Danchev
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
ComboBox
Asked by
Jens
Top achievements
Rank 1
Answers by
Dimitar
Telerik team
Raditya
Top achievements
Rank 1
Ivan Danchev
Telerik team
Share this question
or