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

Filter/Select only after certain number of characters are entered

5 Answers 700 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Philip
Top achievements
Rank 1
Philip asked on 02 Dec 2011, 09:16 PM
I previously used the Telerik MVC combobox control so that it only returns results when at least 3 characters have been entered. I was able to specify this in my controller by simple checking the text string that was passed in the ajax request.

With the KendoUI combobox, I cannot figure out how the text is being passed and what to check for in my controller to see if at least 3 characters have been entered.

Can you provide any assistance with this? Thanks.

UPDATE:

So I found by looking at the AutoComplete control, that I can set the ComboBox to not retrieve results until at least 3 characters are entered by using minLength: 3

I still have the issue on the controller side, however, that I don't want to bring back the entire list...I only want to bring back results that contain the text entered. What do I need to include on the controller side to get the text entered in the ComboBox?

Thanks!

5 Answers, 1 is accepted

Sort by
0
Philip
Top achievements
Rank 1
answered on 02 Dec 2011, 09:44 PM
I tried this in my transport
transport: {
    read: "/Reporting/Client-Reports/_test",
    data: {
        text: function () {
            var ac = $("#test").data("kendoComboBox");
            return ac.value();
        },
        maxRows: 10
    }
}

and then in my controller
public ActionResult _test(string text)
{
    List<Client> clients = new List<Client>();
 
    clients = _clientreportsService.GetClients(text).ToList();
 
    return Json(new SelectList(clients, "ClientId", "ClientName"), JsonRequestBehavior.AllowGet);
}

the _clientreportsService.GetClients(text).ToList(); is what retrieves the results filtered on the "text" parameter


from what I can tell with this though, "text" is not being passed to the controller.
0
Accepted
Petyo
Telerik team
answered on 06 Dec 2011, 01:41 PM
Hi Philip,

By default, the filtering sends filters request parameter which contains the needed information. You can read more about the parameters passed to the server in our documentation.

In addition to that, you can simplify the passed information using the parameterMap function of the transport: 

transport: {
    read: ...,
    parameterMap: function(options)  {
        if (options.filter) {
            return "text=" + options.filter.filters[0].value;
        }
    }
},

Regards,
Petyo
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Philip
Top achievements
Rank 1
answered on 07 Dec 2011, 07:16 PM
Thanks Petyo...that solution works great.
0
Joao
Top achievements
Rank 1
answered on 08 Dec 2011, 12:19 PM
I managed autobind to work with this modification:

                parameterMap: function(options) {
                      if (options.filter) {
                        return "text=" + options.filter.filters[0].value; 
                      }
                      else
                      {
                        return "text=" + $("#test").val();
                      }
                    }
0
Ryan Lege
Top achievements
Rank 1
answered on 12 Sep 2012, 08:50 AM
How do we do this with ODATA? I want to use startswith
Tags
ComboBox
Asked by
Philip
Top achievements
Rank 1
Answers by
Philip
Top achievements
Rank 1
Petyo
Telerik team
Joao
Top achievements
Rank 1
Ryan Lege
Top achievements
Rank 1
Share this question
or