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

Combobox server filtering

3 Answers 734 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Walid
Top achievements
Rank 1
Walid asked on 10 May 2018, 09:01 PM

I am apparently missing something in setting up a combo box, can someone help me out?

I followed the examples, and got to here:

------

        public JsonResult GetItems(string filter)
        {
            List<Item> Items = new List<Item>();
            if (!string.IsNullOrEmpty(filter))
                using (ScratchDBClassesDataContext DB = new ScratchDBClassesDataContext())
                    Items = DB.Items.Where(itm => itm.Name.Contains(filter)).ToList();
            return Json(Items, JsonRequestBehavior.AllowGet);
        }

------

@(Html.Kendo().ComboBox()
        .Name("ItemCombo")
        .DataSource(ds =>
        {
            ds.Read(read =>
            {
                read.Action("GetItems", "Home").Data("FilterValue");
            });
            ds.ServerFiltering(true);
        })
        .DataTextField("Name")
        .DataValueField("ItemID")
        .AutoBind(false)
        .MinLength(3)
        .ClearButton(true)

)
<script>
    function FilterValue() {       
        var ItemCombo = $("#ItemCombo").data("kendoComboBox");
        return { filter: ItemCombo.text() };
    }
</script>

------

 

It works initially - once I type 3 characters, the read action runs and my initial results are shown in the popup.  However, after that, the read action never fires again when I continue typing, so the box never further filters my results. 

 

I put a breakpoint in my controller code as well as an alert in the "FilterValue" function, and I can confirm that the action is not firing.

 

I discovered that if I add ".Filter(FilterType.Contains)" to the combobox configuration, the action fires every time I type after the 3rd character but my controller receives a null value for the filter string. An alert in "FilterValue" shows that ItemCombo.text() has the value I want, but it isn't being sent to the controller.

 

What have I missed here?

3 Answers, 1 is accepted

Sort by
0
Neli
Telerik team
answered on 14 May 2018, 12:29 PM
Hi Walid,

I used the provided snippet to test the behavior on my end. I did not manage to replicate the described problem. On every letter I am entering after the third carachter, the breakpoint in the HomeController -> GetData action is hit and the values are filtered.
May I ask you to modify the attached sample project in order to replicate the behavior the way it is at your end? This way we could troubleshoot locally and provide further assistance. 

Regards,
Neli
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
Tony
Top achievements
Rank 1
answered on 14 May 2018, 04:02 PM

After comparing your code to mine, I was able to get my code working by changing my action signature from

public JsonResult GetItems(string filter)

to

public JsonResult GetItems(string text)

 

 

and removing my Data script.  I was assuming I had to manually provide the filter text through a Data object, but it appears I do not.  Thanks!

0
Tony
Top achievements
Rank 1
answered on 14 May 2018, 04:03 PM
(BTW, this is the original poster, I was accidentally posting under my manager's account originally.)
Tags
ComboBox
Asked by
Walid
Top achievements
Rank 1
Answers by
Neli
Telerik team
Tony
Top achievements
Rank 1
Share this question
or