[英]Kendo grid when create a new row, auto populate fields with values from existing row
I have 5 columns (kendo grid) that gets data from the database. 我有5列(剑道网格),它们从数据库中获取数据。 What I'm trying to do is, whenever I add a new row, I want certain columns to be auto populated dynamically. 我想做的是,每当我添加新行时,我都希望某些列能够动态自动填充。
For example, I have Name, country, state, value, and effDate columns. 例如,我有“名称”,“国家/地区”,“州”,“值”和“ effDate”列。
Name, country, state fields are editable = false
. 名称,国家/地区,州字段editable = false
。 So users are only able to edit value and effDate fields. 因此,用户只能编辑value和effDate字段。
If Name = John, Country = USA, State = Alaska, Value = 123, effDate = 9/11/2019 and when I add a new row, I want Name, country, state fields to be populated with Name - John, Country - USA, State - Alaska. 如果Name = John,Country = USA,State = Alaska,Value = 123,effDate = 9/11/2019,并且当我添加新行时,我希望Name,country,state字段填充Name-John,Country-美国,阿拉斯加州。 Value and effDate should only be empty so that users can add new data. Value和effDate只能为空,以便用户可以添加新数据。
I'm currently using template. 我目前正在使用模板。 I tried this to populate country column, but it's not showing anything. 我尝试使用此方法填充“国家/地区”列,但未显示任何内容。
template: "#= Country #"
Is there a way to pre-populate dynamically when create a new row? 创建新行时,有没有一种方法可以动态地预先填充?
Part of my grid codes model: 我的网格代码模型的一部分:
{
id: "NameKey",
HouseKey: houseKey,
fields: {
Name: { editable: false },
Country: { editable: false },
State: { editable: false },
Value: {
validation: {
pattern: {
value: "^[0-9.]{0,10}$",
message: "Only numbers"
},
required: {
message: "Value is required"
},
}
},
EffDate: { validation: { required: true }, type: "date", format: "{0:MM/dd/yyyy}" },
},
...
part of the columns 列的一部分
columns: [
{ field: "Name", template: "#=(Name== '') ? 'Fields are auto populated' : Name#", title: "Name", width: 250 },
{ field: "Country", template: "#=(Country== '') ? 'Fields are auto populated' : Countr#", title: "Country", width: 210 },
{ field: "State", template: "#=(StateName == '') ? 'Fields are auto populated' : State#", title:"State", width: 200 },
{ field: "Value", title:"Value", width: 200 },
{
field: "EffDate", title;"Date", template: "#= kendo.toString(kendo.parseDate(data.EffDate, 'yyyy-MM-dd'), 'MM/dd/yyyy') #", width: 140
},
],
You can use beforeEdit
event to achieve that behaviour. 您可以使用beforeEdit
事件来实现该行为。 That event is called whenever user tried to edit or create a new entry in the grid. 每当用户尝试在网格中编辑或创建新条目时,都会调用该事件。 It receives the current model, which you can change according to your needs: 它会收到当前模型,您可以根据需要进行更改:
beforeEdit: function(e) {
let model = e.model;
if (model.isNew()) {
model.Name = "John";
model.Country = "USA";
model.State = "Alaska";
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.