简体   繁体   English

基于网格的列值的Kendo UI网格编辑器

[英]Kendo UI Grid Editors Based on the Column Values of the Grid

I found this article in the Kendo UI documentation and it's almost identical to my issue that I'm stuck with. 在Kendo UI文档中找到了这篇文章,它与我坚持的问题几乎相同。 Once I open in Dojo I edit some lines of code, especially I change to editable:"inline" mode and make a dropdown list for type column. 在Dojo中打开后,我将编辑一些代码行,尤其是更改为editable:"inline"模式并为type column创建一个下拉列表。 But it seem the code not working as I expected. 但是似乎代码无法按我预期的那样工作。

Any idea why Editor column not react after I change the value type from the dropdown list. 我从下拉列表中更改值type后,为什么Editor列不响应的任何想法。 It worked if I Update first, then Edit back the grid. 如果我先进行更新,然后再编辑回网格,则它会起作用。

Here I provide a Demo due to related situation 由于相关情况,在此我提供一个演示

Appreciate your help. 感谢您的帮助。 Thanks 谢谢

It's working as intended how you have it coded. 它按预期方式工作,如何编码。 The editor for the column is only called when the edit event is triggered. 仅在触发编辑事件时才调用列的编辑器。 If you want the editor field to change dynamically based on the type that you have selected while already in editing mode , you'll have to update the kendoDropDownList on your type editor to make use of the change event to then change the other editor. 如果要使编辑器字段根据已处于编辑模式下的类型而动态更改,则必须更新类型编辑器上的kendoDropDownList,以利用change事件来更改另一个编辑器。

function typeEditor(container, options) {
        $('<input id="' + options.field + '" name="type" required dataTextField="type" dataValueField="type" data-bind="value:' + options.field + '"/>')
          .appendTo(container)
          .kendoDropDownList({
            optionLabel: "- Select Type -",
            dataTextField: "settingTypeName", 
            dataValueField:  "settingTypeName", 
            dataSource: settingTypeData,
            change: function(e){
              console.log(this.value());
              //UPDATE EDITOR HERE BASED ON VALUE
              //From your example, value is going to be dropdown, date, string, etc.
            }
        }).data('kendoDropDownList');
}

Edit in response to comment: I'm not sure what you mean by you aren't able to get the value from the dropdownlist. 编辑以回应评论:我不确定您的意思是您无法从下拉列表中获取值。 The code above is literally writing the value to the console. 上面的代码实际上是将值写入控制台。 You're next step would be to select the element that you want to change, empty it, and add a new editor in it's place. 下一步是选择要更改的元素,将其清空,然后在该位置添加新的编辑器。

...
change: function(e){
    switch(this.value()) {
        ...
        case "string":
            $("[data-container-for=editor]").empty()
            $("<input id='editor' name='editor' type='text' class='k-textbox'>")
              .appendTo($("[data-container-for=editor]"));
            break;
        ...
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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