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

Kendo DropDownList Filter Losing Value

7 Answers 1514 Views
DropDownList
This is a migrated thread and some comments may be shown as answers.
Joey
Top achievements
Rank 1
Joey asked on 21 Jun 2016, 04:57 PM

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))

7 Answers, 1 is accepted

Sort by
0
Veselin Tsvetanov
Telerik team
answered on 23 Jun 2016, 01:24 PM
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
0
Joey
Top achievements
Rank 1
answered on 24 Jun 2016, 01:33 PM

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.  

0
Veselin Tsvetanov
Telerik team
answered on 27 Jun 2016, 01:15 PM
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
0
Joey
Top achievements
Rank 1
answered on 28 Jun 2016, 07:04 PM
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?
0
Veselin Tsvetanov
Telerik team
answered on 29 Jun 2016, 10:59 AM
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
0
Joey
Top achievements
Rank 1
answered on 29 Jun 2016, 02:21 PM

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?

0
Veselin Tsvetanov
Telerik team
answered on 01 Jul 2016, 10:38 AM
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
Tags
DropDownList
Asked by
Joey
Top achievements
Rank 1
Answers by
Veselin Tsvetanov
Telerik team
Joey
Top achievements
Rank 1
Share this question
or