How to use ComboBox as Kendo UI grid column?

前端 未结 4 1632
时光说笑
时光说笑 2021-01-17 02:03

I\'m working with a kendo grid and I\'m trying to make Name field a combobox that has it\'s own datasource. I\'m not getting a javascript error, but when I go to edit the na

4条回答
  •  太阳男子
    2021-01-17 02:34

    I am using MVC4
    In grid:

    columns.Bound("Productname").Title("Productname")                    
       .Width(200)                                           
       .EditorTemplateName(Productname);
    

    Create EditorTemplateName = Productname.
    In view share:

    @(Html.Kendo().ComboBox()
                 .Name("Ten_dvt")
                 .DataValueField("Ten_dvt")
           .DataTextField("Ten_dvt")
           .Filter(FilterType.Contains)
            .HighlightFirst(true)
           .DataSource(source =>
           {
               source.Read(read =>
               {
                   read.Action("Dm_dvt", "Combo");
               });
           })   .Events(e => e.Select("Select_Ma_dvt").Change("Change_Ma_dvt"))
       .HeaderTemplate("
    " + @Tcommont("Ma") + "" + @Tcommont("Ten") + "
    ") .Template("
    " + "#: data.Ma_dvt #" + "" + "#: data.Ten_dvt #" + "
    " + "
    ;#:data.Ma_dvt#;#:data.Ten_dvt#;
    ") )

    Then form edit using:

    function Change_Ma_dvt(e) {  if (this.selectedIndex == -1) {
                                  var grid = $("#gridItem2").data("kendoGrid");
                                  var _dataItem = grid.dataItem(grid.select());
                                  _dataItem.set("Ten_dvt", "");
                                  _dataItem.set("Ma_dvt", "");
                              } }
    

    and

    function Select_Ma_dvt(e) {    var _Arr = e.item.text().split(";");
                              var grid = $("#gridItem2").data("kendoGrid");
                              var _dataItem = grid.dataItem(grid.select());
                              _dataItem.set("Ma_dvt", _Arr[1]);
                              break; }
    

    last grid show name and you choose then Id or Ma will be choose hide

提交回复
热议问题