簡體   English   中英

Kendo ui帶有下拉列表和網格

[英]Kendo ui with a dropdownlist and a grid

誰能幫幫我,我之前已經發布過相同的問題,但我無法獲得答案。 我有一個網格,內部有一個下拉列表,它工作正常,但網格中的列數很少,這取決於下拉列表,所以任何人都可以告訴我,當dropdowlist的選定值更改時如何更改列的值。 在我的網格中,我有一個StudentNumber作為下拉列表,StudentGivenName是一列取決於學生編號的列。 我正在使用asp.net mvc我找不到答案

<%: Html.Kendo().Grid<SSTS.Models.FaresBasedViewModel>()
.Name("grid2")
      .Columns(columns =>
      {
          // columns.Bound(student => student.CustomerName);
    //      columns.Bound(student => student.StudentNumber).Width(150); ;//.ClientTemplate("#=CustomerNames.CustomerName#").Width(160);
          columns.ForeignKey(p => p.StudentNumber, (System.Collections.IEnumerable)ViewData["students"], "StudentNumber", "StudentNumber")
          .Title("StudentNumber").Width(150);
          columns.Bound(student => student.StudentGivenName).Width(150); ;//.ClientTemplate("#=CustomerNames.CustomerName#").Width(160);
          columns.Bound(student => student.DateGovernmentFunded).Width(150); ;//.ClientTemplate("#=CustomerNames.CustomerName#").Width(160);
          columns.Bound(student => student.SectionNumber).Width(150); ;//.ClientTemplate("#=CustomerNames.CustomerName#").Width(160);
          columns.Bound(student => student.Description).Width(150); ;//.ClientTemplate("#=CustomerNames.CustomerName#").Width(160);
          columns.Bound(student => student.Distance).Width(150); ;//.ClientTemplate("#=CustomerNames.CustomerName#").Width(160);
          columns.Bound(student => student.FareNumber).Width(150); ;//.ClientTemplate("#=CustomerNames.CustomerName#").Width(160);
          columns.Bound(student => student.FareType).Width(150); ;//.ClientTemplate("#=CustomerNames.CustomerName#").Width(160);
          columns.Bound(student => student.TopeUpCode).Width(150); ;//.ClientTemplate("#=CustomerNames.CustomerName#").Width(160);
          columns.Bound(student => student.ApplicationID).Width(150); ;//.ClientTemplate("#=CustomerNames.CustomerName#").Width(160);



            columns.Command(commands =>
          {
              commands.Edit(); // The "edit" command will edit and update data items
              commands.Destroy(); // The "destroy" command removes data items
          }).Title("Commands").Width(150);
      })
      .ToolBar(toolbar => toolbar.Create()) // The "create" command adds new data items
      .Editable(editable => editable.Mode(GridEditMode.InLine)) // Use inline editing mode
      .DataSource(dataSource =>
          dataSource.Ajax()
            .Model(model =>
            {
                model.Id(student => student.FareBaseID); // Specify the property which is the unique identifier of the model

                model.Field(p => p.StudentNumber).DefaultValue("");   //    model.Field(student => student.StudentNumber).Editable(false); // Make the studentID property not editable

          //      model.Field(p => p.CustomerNames).DefaultValue(
           //         ViewData["defaultCategory"] as KendoGridAjaxEditing2.Models.CustomerNamesViewModel);


            })
                        .Create(create => create.Action("FaresBased_Create", "ServiceUse")) // Action invoked when the user saves a new data item
                                                .Read(read => read.Action("FaresBased_Read", "ServiceUse"))  // Action invoked when the grid needs data
                                    .Update(update => update.Action("FaresBased_Update", "ServiceUse"))  // Action invoked when the user saves an updated data item
                                    .Destroy(destroy => destroy.Action("FaresBased_Destroy", "ServiceUse")) // Action invoked when the user removes a data item
      )
          .Pageable().Scrollable()

%>

一般來說,我要做的是

  1. 為下拉列表創建自定義編輯器
  2. 編寫一個函數以綁定到下拉列表的change事件 (另請參見MVC包裝器的相應文檔 ),該函數根據所選的下拉列表值設置其他列值

您可以通過使用$(e.sender).element.closest("tr") 從網格和相關的<tr> 獲取下拉列表綁定的dataItem

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM