简体   繁体   中英

Kendo UI MVC DropDownList Focus For Filtering

I am using MVC Razor and Telerik Kendo MVC. I have a dropdownlst that I would like to automatically set focus on so that the user can immediately begin typing and filtering for the desired value. The ddl is:

@(Html.Kendo().DropDownList()
    .Name("ddlLocations")
    .Filter("contains")
    .BindTo(Model.Locations)
    .DataTextField("Text")
    .DataValueField("Value")
    .Events(events => events.Change("onChange"))
    .HtmlAttributes(new { style = "width:100%" })
    .Value(Model.Exception.LocationIDCouponTypeStatus)
)

I have a similar project in ASP.NET WebForms and what I did in Javascript is:

 var comboBox = $find("<%=ddl.ClientID %>");
 comboBox._inputDomElement.select();

This focused on the part of the control that tells it to start filtering when the user begins to type. It doesn't seem to be translating to the MVC version.

var comboBox = $("#ddlLocations").data("kendoDropDownList");
comboBox._inputDomElement.select();

Any ideas? Thanks in advance.

You need to open dropdownlist first:

.Events(p => p.DataBound("function(e){ this.open(); this.filterInput.focus(); }"))

Alternatives:

$(function(){
    var dd = $("#ddlLocations").data("kendoDropDownList");
    dd.open();
    dd.filterInput.focus();
});

or

.Events(p => p.DataBound("function(e){ setTimeout(function(){ this.open(); this.filterInput.focus(); }, 500); }"))

比这容易得多的是,Kendo已经具有focus()函数,只需执行comboBox.focus()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM