简体   繁体   中英

Kendo ui with a dropdownlist and a grid

can anyone help me out i have already posted the same question before but i am not able to get the answer. I have a grid and inside i have a dropdownlist which is working fine but i have few columns in the grid which depends on the dropdownlist so can anyone tell me how can i change the value of the columns when the selected value of dropdowlist changes. In my grid i have a studentnumber as a dropdownlist and StudentGivenNameis a column which depends on the student number . I am using asp.net mvc i am not able to find the answer

<%: 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()

%>

In general, what I would do is

  1. create a custom editor for your dropdown-column
  2. write a function to bind to the dropdown's change event (also see the respective docs for the MVC wrappers ) which sets the other column values depending on the selected dropdown value

You can get the dataItem the dropdown is bound to from the grid , and the relevant <tr> by using $(e.sender).element.closest("tr") .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM