[英]Kendo grid when create a new row, auto populate fields with values from existing row
我有5列(劍道網格),它們從數據庫中獲取數據。 我想做的是,每當我添加新行時,我都希望某些列能夠動態自動填充。
例如,我有“名稱”,“國家/地區”,“州”,“值”和“ effDate”列。
名稱,國家/地區,州字段editable = false
。 因此,用戶只能編輯value和effDate字段。
如果Name = John,Country = USA,State = Alaska,Value = 123,effDate = 9/11/2019,並且當我添加新行時,我希望Name,country,state字段填充Name-John,Country-美國,阿拉斯加州。 Value和effDate只能為空,以便用戶可以添加新數據。
我目前正在使用模板。 我嘗試使用此方法填充“國家/地區”列,但未顯示任何內容。
template: "#= Country #"
創建新行時,有沒有一種方法可以動態地預先填充?
我的網格代碼模型的一部分:
{
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}" },
},
...
列的一部分
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
},
],
您可以使用beforeEdit
事件來實現該行為。 每當用戶嘗試在網格中編輯或創建新條目時,都會調用該事件。 它會收到當前模型,您可以根據需要進行更改:
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.