如何从组合框更新 KendoGrid

How to update KendoGrid from combobox

我正在使用 Kendo UI 在 ASP.NET MVC 中编写 Web 应用程序。我正在 Kendo 网格中可视化数据,如下所示:

 @(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> 的更改事件触发网格更新。我怎样才能做到这一点?我从昨天开始尝试了几种可能性,但都没有成功。

在没有看到您的组合框代码的情况下,我会执行以下操作:

查看

@(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 评论:

I didn't specify directly the parameters in the read.Action method, but instead I used the handler function like in this post telerik.com/forums/… Now when changing the combobox value the action fires with right parameters