首页 > 解决方案 > Kendo UI 下拉列表已选中

问题描述

我有一个剑道 ui 功能下拉列表,它将在网格列编辑器中调用。我的问题,默认情况下如何在编辑功能中添加新记录时显示“” 。目前添加新记录时显示为空。

Dojo 中的演示

在这里,我提供了一个工作演示。谢谢你

标签: javascriptkendo-uikendo-grid

解决方案


如果我理解正确,您只需在模型中的价格添加默认值?

"Price": {type: "string", defaultValue: "y" }, 

我包括了整个功能,以防万一:

$(function() {
  $("#grid").kendoGrid({
    dataSource: {
      data: [
       { Name: "Young John", Price: "y" },
       { Name: "John Doe", Price: "n" },
       { Name: "Old John", Price: "y" }
      ],
      schema: {
        model: {
          id: "id",
          fields: {
            "id": { type: "number" }, 
            "Price": {type: "string", defaultValue: "y" }, 
          }
        }
      }
    },
    editable: "inline",
    toolbar: ["create"],
    columns: [{ field: "Name"}, 
              { field: "Price",
                        template: "#=(data.Price == 'y' ? 'Yes' : 'No')#",
                editor: radioPrice
              } ],
    edit: function(e) {     
       if (e.model.isNew()) {       
                        e.model.Price = 'y';
       }
    }
  });
});

推荐阅读