How to set filter property through javascript or Jquery for a kendo dropdown

本秂侑毒 提交于 2019-12-12 06:50:00

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!