Kendo DropDownList Filter Losing Value

8 posts, 0 answers
  1. Joey
    Joey avatar
    5 posts
    Member since:
    Apr 2016

    Posted 21 Jun Link to this post

    So I have a dropdown list that initially populates with 10 values (the most common values for race) However, when the user starts typing, it searches the entire list of values(around 900) for a match.  I didn't want load 900 values into a dropdown list so it uses server filtering and goes back to the server and searches for a match.  I can select  a race and this populates the dropdown list appropriately.  However, if i reselect the dropdownlist, it loses the value, and only shows the initial 10.  Is there a way where i can set the filter for the dropdown list to populate on click, so it will go to the server and bring back the match so it'll show that in the list and not lose its value?

    @(Html.Kendo().DropDownListFor(m => m.Race.Id)
    .OptionLabel("--Select--")
     .DataTextField("Description")
    .Value(Model.Race.Id.ToString())
    .Text(Model.Race.Description)
    .DataValueField("Id")
    .HtmlAttributes(new { style = "width: 100%;", tabindex = "31" })
    .Filter("contains")
    .DataSource(source =>
    {
        source.Read(read =>
      {
         read.Action("GetRaceValueSet", "Person");
     
      }).ServerFiltering(true);
     })
     .AutoBind(false))
  2. Veselin Tsvetanov
    Admin
    Veselin Tsvetanov avatar
    290 posts

    Posted 23 Jun Link to this post

    Hello Joey,

    I am not sure if I understood right what you are trying to achieve. Are you trying to do the following:
    - Open the DropDownList - at this stage you have the default 10 values;
    - Type in the input area, so filtered result has been returned;
    - Select one of the returned results (different from the default 10 results);
    - Click outside the DropDown;
    - Click the DropDoun arrow - when the drop-down opens only the initial 10 values are shown and the selected is not;

    If this is your scenario, the reason for the observed is the fact that the input field at this point is empty, so the control returns only the default results. Instead of returning default values, I would suggest you to use Virtualization with paging and filtering. You will simply have to put your default values on at the begging of the returned collection, so they will be populated initially in the drop-down of the widget.

    If the above does not match your scenario, could you please explain a bit more in detail which are the steps that you follow and what is exactly the bottleneck?

    Besides that, given that you need filtering and the ability to type in the input area, I would suggest you try the ComboBox widget / helper instead of DropDownList. The ComboBox is a drop-down widget that by design offers typing in the input area. It also offers server filtering and virtualization.

    Regards,
    Veselin Tsvetanov
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. UI for ASP.NET MVC is VS 2017 Ready
  4. Joey
    Joey avatar
    5 posts
    Member since:
    Apr 2016

    Posted 24 Jun in reply to Veselin Tsvetanov Link to this post

    Yes the first scenario you described is what I am trying to accomplish.  However, the last step, since I have selected a previous item in the dropdown (different than the initial 10 values), I would not expect to lose that current value when I click the dropdown but I do.  

     

    Regarding the ComboBox widget, I was under the impression that this widget allows users to type in free text and save if there is no match.  I only want my users to be able to select from a defined set of items returned from the database.  

  5. Veselin Tsvetanov
    Admin
    Veselin Tsvetanov avatar
    290 posts

    Posted 27 Jun Link to this post

    Hello Joey,

    Even if it allows typing free text, the ComboBox widget does not allow users to save random text as new ComboBox item. They will be only allowed to select one of the predefined (existing) values / items.

    Regards,
    Veselin Tsvetanov
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  6. Joey
    Joey avatar
    5 posts
    Member since:
    Apr 2016

    Posted 28 Jun in reply to Veselin Tsvetanov Link to this post

    But it gives the appearance that it allows the user to save their own input.  That is why I went with the first scenario.  Any idea how to accomplish this?
  7. Veselin Tsvetanov
    Admin
    Veselin Tsvetanov avatar
    290 posts

    Posted 29 Jun Link to this post

    Hi Joey,

    No mater if you use DropdownList or ComboBox, I would recommend you to remove the following lines from the initialization of the widget:
    .Value(Model.Race.Id.ToString())
    .Text(Model.Race.Description)

    The above are not needed and may cause issues, when used with strongly typed HTML helpers as the DropDownListFor.

    Moreover, I would suggest you to use the virtualization functionality of the control, to return only a limited number of results from the server. 

    Please, let me know if you face the same issue after implementing the modifications suggested.

    Regards,
    Veselin Tsvetanov
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  8. Joey
    Joey avatar
    5 posts
    Member since:
    Apr 2016

    Posted 29 Jun in reply to Veselin Tsvetanov Link to this post

    The reasoning behind the 

    .Value(Model.Race.Id.ToString())
    .Text(Model.Race.Description)

    was because of .Autobind(false).  95% of the time, there would be no need to to have a call to the db to get the value set.  When there are about 15 of these dropdownlists, you can see why I wouldn't want them running everytime the user hits the page.  Would it be better to set the Name() instead of using the strongly typed helper?

  9. Veselin Tsvetanov
    Admin
    Veselin Tsvetanov avatar
    290 posts

    Posted 01 Jul Link to this post

    Hi Joey,

    If you want to set the .Value and the .Text configurations of the DropDownList, I would recommend you to avoid using the strongly typed version of the HTML helper. 

    Regards,
    Veselin Tsvetanov
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top
UI for ASP.NET MVC is VS 2017 Ready