代码之家  ›  专栏  ›  技术社区  ›  Pierpaolo Paris

如何从组合框更新KendoGrid

  •  1
  • Pierpaolo Paris  · 技术社区  · 10 年前

    我正在用ASP。NET MVC使用Kendo UI。我将剑道网格中的数据可视化如下:

     @(Html.Kendo().Grid<MyModel>()
      .Name("grid")
      .DataSource(dataSource => dataSource // Configure the grid data source
          .Ajax() // Specify that ajax binding is used
          .Read(read => read.Action("ReadAction", "MyController", new { /*route values*/ }))
        )
      .Columns(columns =>
      {
          columns.Bound(n => n.Month).Title("Month").ClientTemplate("<input type='hidden' value='#=Month#' id='hfMonth'/>").Hidden();
          columns.AutoGenerate(true);          
    
      })
      .Pageable()
      .Sortable()
    

    现在我需要根据 <select> 。我该怎么做?我从昨天开始尝试了几种可能性,但都没有成功。

    1 回复  |  直到 10 年前
        1
  •  0
  •   hutchonoid    10 年前

    如果没有看到组合框的代码,我将执行以下操作:

    看法

    @(Html.Kendo().ComboBox()
          .Name("combo")
          .DataTextField("Text")
          .DataValueField("Value")
          .BindTo(new List<SelectListItem>() {
              new SelectListItem() {
                Text = "Foo", Value = "1"   
              },
              new SelectListItem() {
                Text = "Bar", Value = "2"   
              },
              new SelectListItem() {
                Text = "Baz", Value = "3"   
              }
          })
      .Events(events =>
      {
        events.Change("onChange");
      })
    )
    

    JavaScript

    function onChange(e) {
    
      var grid = $("#grid").data("kendoGrid");
      // if the selected value is not needed
      grid.dataSource.read();
    
      // if the selected value is needed use below instead
      // changing the route parameter to match yours
      var selectedValue = this.Value();
      grid.dataSource.read({ id : selectedValue });
    }
    

    使现代化

    根据@PierpaoloIlConteParis评论:

    我没有在读取中直接指定参数。Action方法,但我使用了处理程序函数,如本文所述 telerik.com/forums/… 现在,当更改组合框值时,将使用正确的参数触发操作