javascript 有什么方法可以在剑道网格自定义弹出模板中设置默认值?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18806374/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 13:17:27  来源:igfitidea点击:

Any way to set a default value in a kendo grid custom popup template?

javascriptjquerykendo-uikendo-grid

提问by user1783490

I'm using a custom edit popup template for my Kendo grid, the Add New Row and edit use the same template, when the custom popup template is opened on Add New Row, is there any way to set a default value for one of the fields?

我正在为我的 Kendo 网格使用自定义编辑弹出模板,添加新行和编辑使用相同的模板,当在添加新行上打开自定义弹出模板时,有没有办法为其中一个设置默认值领域?

采纳答案by Vladimir Iliev

Default values for the fields should be set in the schema.model definition of the dataSource:

字段的默认值应在数据源的 schema.model 定义中设置:

schema.model Object kendo.data.ModelThe data item (model) configuration.

schema.model Object kendo.data.Model数据项(模型)配置。

If set to an object, the Model.define method will be used to initialize the data source model.

如果设置为对象,则 Model.define 方法将用于初始化数据源模型。

If set to an existing kendo.data.Model instance, the data source will use that instance and will not initialize a new one.

如果设置为现有的 kendo.data.Model 实例,数据源将使用该实例并且不会初始化新的实例。

Example - set the model as a JavaScript object

示例 - 将模型设置为 JavaScript 对象

<script>
var dataSource = new kendo.data.DataSource({
  schema: {
    model: {
      id: "ProductID",
      fields: {
        ProductID: {
          //this field will not be editable (default value is true)
          editable: false,
          // a defaultValue will not be assigned (default value is false)
          nullable: true
        },
        ProductName: {
          //set validation rules
          validation: { required: true }
        },
        UnitPrice: {
          //data type of the field {Number|String|Boolean|Date} default is String
          type: "number",
          // used when new model is created
          defaultValue: 42,
          validation: { required: true, min: 1 }
        }
      }
    }
  }
});
</script>

Example - set the model as an existing kendo.data.Model instance

示例 - 将模型设置为现有的 kendo.data.Model 实例

<script>
var Product = kendo.data.Model.define({
  id: "ProductID",
  fields: {
    ProductID: {
      //this field will not be editable (default value is true)
      editable: false,
      // a defaultValue will not be assigned (default value is false)
      nullable: true
    },
    ProductName: {
      //set validation rules
      validation: { required: true }
    },
    UnitPrice: {
      //data type of the field {Number|String|Boolean|Date} default is String
      type: "number",
      // used when new model is created
      defaultValue: 42,
      validation: { required: true, min: 1 }
    }
  }
});
var dataSource = new kendo.data.DataSource({
  schema: {
    model: Product
  }
});
</script>