Set initial value if serverfiltering is true

4 posts, 0 answers
  1. Jens
    Jens avatar
    1 posts
    Member since:
    Dec 2016

    Posted 14 Nov Link to this post

    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!
  2. Dimitar
    Admin
    Dimitar avatar
    225 posts

    Posted 16 Nov Link to this post

    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.
  3. Raditya
    Raditya avatar
    3 posts
    Member since:
    Jan 2016

    Posted 29 Nov in reply to Dimitar Link to this post

    Hi,

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

    Thanks

    Best regards,

    Raditya

  4. Ivan Danchev
    Admin
    Ivan Danchev avatar
    1332 posts

    Posted 01 Dec Link to this post

    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.
Back to Top