使用动态下拉列表进行KendoGrid内联编辑

时间:2015-06-18 15:01:37

标签: kendo-ui

In this demo,如果点击该类别,您会看到一个下拉列表来选择该值。我需要的是让下拉列表的值取决于条件,因此当您打开不同行的下拉列表时,您可能会获得不同的列表。

目前我创建了一行,我有值填充下拉列表,但我不确定如何使用这些值。

这是我定义列的方式(我不会使用模板):

{ field: "source", title: "Source", width: "180px", editor: srcEditor},

这是编辑:

function srcEditor(container, options) {
   $('<input required data-text-field="name" data-value-field="id" 
         data-bind="value:' + options.field + '"/>')
            .appendTo(container)
            .kendoDropDownList({
                dataSource: sources,
                dataTextField: "name",
                dataValueField: "id"
        });
    }

仅当所有行具有相同的下拉列表时才有效,但是如何为每行声明不同的srcEditor

1 个答案:

答案 0 :(得分:2)

通过这个声明:

  

为每一行声明一个不同的srcEditor

你要么想要

  1. 完全每行不同的数据源
  2. 拥有相同的数据源,但如果某些条件符合
  3. 则执行某些过滤
  4. 样式(此处仅添加类/样式)
  5. 数字1的解决方案修改你的categoryDropDownEditor函数,做一些条件设置数据源的url并添加不同的url:

    <DataGridTemplateColumn>
      <DataGridTemplateColumn.CellTemplate>
        <DataTemplate>
          <Label Content="{Binding CategoryName,
                     Mode=TwoWay,
                     UpdateSourceTrigger=LostFocus}"
                 Foreground="{Binding Foreground,
                     RelativeSource={RelativeSource Mode=FindAncestor,
                         AncestorLevel=1, 
                         AncestorType={x:Type DataGridCell}}}"
                 Width="150"/>
        </DataTemplate>
      </DataGridTemplateColumn.CellTemplate>
    </DataGridTemplateColumn>
    

    数字2的解决方案修改categoryDropDownEditor函数并添加条件并在参数图上执行(sor / filter),此处为link

    function categoryDropDownEditor(container, options) {
            var model = options.model;
            var tempDataSource = new kendo.data.DataSource({
                type: "odata",
                transport: {
                    read: ( (model.UnitPrice > 20) ? urlConst.restServiceA : urlConst.restServiceB),
                }
            });
    }
    
相关问题