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

Datasource request fires twice on MultiSelect

2 Answers 514 Views
MultiSelect
This is a migrated thread and some comments may be shown as answers.
wortho
Top achievements
Rank 2
wortho asked on 10 Jan 2018, 10:38 PM

I have a simple multiselect like so:

@(Html.Kendo().MultiSelectFor(x => x.CourseId)
      .DataValueField("Id")
      .DataTextField("Name")
       .Placeholder("Select Course...")
      .ClearButton(false)
      .DataSource(source =>
      {
          source.Read(read =>
          {
              read.Action("GetCourseCodeList", "Home");
          })
          .ServerFiltering(true);
      })
      .MaxSelectedItems(1)
      .HtmlAttributes(new { @class = "" }))

When I enter text, the search is submitted once with the text entered, then a second time with the Placeholder text, or if no Placeholder, with empty string.

public JsonResult GetCourseCodeList(string text, int categoryId=0)
{
    var items = _courseData.Where(x =>
        x.Name.Contains(text) &&
        (categoryId == 0 || x.CategoryId == categoryId)).OrderBy(x => x.Name).ToList();
 
    var userinput = text;
 
    var result = new JsonResult
    {
        JsonRequestBehavior = JsonRequestBehavior.AllowGet,
        Data = items
    };
    return result;
}

A sample project replicating the issue is here : https://github.com/SteveWortho/TLCKendoTest 

It must be something simple I am doing wrong - any advice appreciated.

Using;

VS2017 Pro Version 15.5.1

KendoUI MVC 2017.3.1026

Chrome Version 63.0.3239.132 or Microsoft Edge or FireFox. Issue is repeatable.

So I must be firing the onChange event a second time with some of this configuration maybe?

But it is such a simple example.

Thanks in advance,

Steve

 

 

 

2 Answers, 1 is accepted

Sort by
0
wortho
Top achievements
Rank 2
answered on 11 Jan 2018, 05:25 AM

Oh - found the issue, it was simple, no results.

Things I learned in case it helps anyone else.

* If there are no matching search results, the criteria is cleared and it fires the search again, hence my impression it was firing twice.

* Why was there no search results when I was entering a simple w or a? Because it was case sensitive.

At least - that is what I think was going on. I did experience also;

* That the text parameter that is submitted by default is not done so when you add the .Data("onAdditionalData").

(In my case with multiple dynamic selects, it is a fail because I only know the control name at runtime, but this is nothing to do with the issue above  - just noting it in case it helps someone.)

0
Chris
Top achievements
Rank 1
Veteran
Iron
Iron
answered on 07 Apr 2022, 09:01 AM
The reason known, but the solution still unknown.
Yanislav
Telerik team
commented on 11 Apr 2022, 07:12 AM

I've reviewed the case but unfortunately, I'm unable to reproduce the problem mentioned related to sending the Placeholder value. About the request which is sent with no search term, it is performed because, in the event of a subsequent search, the data source must contain all possible results. However, in case the desired result is to prevent the filtering, if there is no value entered you could try to prevent the default behavior of the Filter event : 

.Events(ev=>ev.Filtering("onFiltering"))

    function onFiltering(e) {
        if (e.filter.value === '') {
            e.preventDefault();
        }
    }

About the request sent on 'focusout' it is a known issue and it is logged in our public GitHub issue tracker: 

https://github.com/telerik/kendo-ui-core/issues/6361

Please subscribe to the issue in order to be notified in a timely manner when there is any update.

 

Tags
MultiSelect
Asked by
wortho
Top achievements
Rank 2
Answers by
wortho
Top achievements
Rank 2
Chris
Top achievements
Rank 1
Veteran
Iron
Iron
Share this question
or