问题
I have a kendo dropdown list in cshtml. I wanted to set filter property in Jquery or javasctipt. Could you please tell me how to acheive this? Appreciate your help on this.
@(Html.Kendo().DropDownList()
.Name("movies")
.DataTextField("Text")
.DataValueField("Value")
.HtmlAttributes(new { style = "width: 100%" })
.BindTo(new List<SelectListItem>()
{
new SelectListItem() {
Text = "The Shawshank Redemption", Value ="1"
},
new SelectListItem() {
Text = "The Godfather", Value ="2"
},
new SelectListItem() {
Text = "The Godfather: Part II", Value ="3"
},
new SelectListItem() {
Text = "Il buono, il brutto, il cattivo.", Value ="4"
},
new SelectListItem() {
Text = "Pulp Fiction", Value ="5"
},
new SelectListItem() {
Text = "12 Angry Men", Value ="6"
},
new SelectListItem() {
Text = "Schindler's List", Value ="7"
},
new SelectListItem() {
Text = "One Flew Over the Cuckoo's Nest", Value ="8"
},
new SelectListItem() {
Text = "Inception", Value ="9"
},
new SelectListItem() {
Text = "The Dark Knight", Value ="10"
}
})
)
回答1:
UPDATE: if filter was not set upon creation, destroy and re-initialize with the filter
In JavaScript/jQuery get the dropdownlist and call destroy():
var dropdownlist = $("#movies").data("kendoDropDownList");
dropdownlist.destroy();
Then recreate with filter:
$("#products").kendoDropDownList({
dataTextField: "ProductName",
dataValueField: "ProductID",
dataSource: {
transport: {
read: {
dataType: "jsonp",
url: "https://demos.telerik.com/kendo-ui/service/Products",
}
}
},
filter: filt
});
DEMO
来源:https://stackoverflow.com/questions/46033614/how-to-set-filter-property-through-javascript-or-jquery-for-a-kendo-dropdown