我的問題與我的網格更新相關。這是我目前併網發電的計劃:Kendo UI Grid:添加包含影響模板的變量的行
leTle[0] = {index : 1, tle : tleId, nom : nomChamp, estar : "", fige : tleFixe, position : positionParam, longueur : longueurParam};
var fige;
if (tleFixe == "true")
fige = true;
else
fige = false;
$("#" + theId).kendoGrid({
columns:[{
field: "index",
title: "Index",
template: "<span style='font-size: 12px;' title='#= index #'>#= index # </span>",
width: 40
},{
field: "tle",
title: "TLE Id",
template: "<span style='font-size: 12px;' title='#= tle #'>#= tle # </span>",
width: 100
},{
field: "nom",
title: "Intitulé",
template: "<span style='font-size: 12px;' title='#= nom #'>#= nom # </span>"
},{
field : "position",
title : "Position",
width : 70,
attributes : {
"class" : fige ? " " : "fondRougePale"
}
},{
field : "longueur",
title : "Longueur",
width : 70,
attributes : {
"class" : fige ? " " : "fondRougePale"
}
},{
field :"estar",
title :"Estar",
template: "<span class='eStar'><input class='inputeStar' disabled type='text' /> </span>",
width : 250
},{
command: {
name : "destroy",
template: "<a class=\"btn btn-warning btn-mini k-grid-delete\">"
+ "<i class=\"icon-minus-sign icon-white\"></i></a>"
},
title: " ",
width: 40
}
],
dataSource: {
data: leTle,
schema: {
model: {
fields: {
tle: {editable: false},
nom: {editable: false},
estar: {editable: false},
longueur: {editable: fige},
position: {editable: fige}
}
}
}
},
editable: {
mode: "incell",
confirmation: false
},
scrollable : false
});
正如你所看到的,我的一些細胞可以,如果我的變量「FIGE」是等於假被禁用。當我嘗試使用基本數據源手動編寫我的網格時,網格沒問題。一排排,當細胞必須被禁用時,它們是。
不幸的是,當我嘗試在構建網格後添加行時,我的變量從不包括單元格設置的時間。
下面是代碼:
var vgrid = $("#tleSelected").data("kendoGrid");
var datasource = vgrid.dataSource;
var nbLines = vgrid.dataSource.total();
//Booleen de test
if (fige == "true")
tfige = true;
else
tfige = false;
var newRecord = { index : nbLines+1, tle : tleId, nom: nomChamp, estar: "", position: position, longueur: longueur, fige: tfige}
datasource.insert(newRecord);
所以,我在的情況下我的變量都不錯,但新線都沒有。
而不是破壞我的網格,並在更新數據後重建它們,你知道這種情況下的解決方案嗎?
非常感謝。
謝謝,我現在試試你的小費。我沒有想到在#=#中使用一個函數。 – jodu
所以,當我在你建議的Columns字段中添加一個類時,它是可以的。 但是,當我想使用相同的過程來更正schema.model.fields.editable時,這並不好。我想我會直接使用data-role =「editable」... – jodu
對不起,我現在太累了(編寫10Hrs的代碼)。我認爲你應該使用[數據源對象](http://docs.kendoui.com/api/framework/datasource)並將其綁定到你的網格,然後每次你編輯或添加或從你的數據源中刪除它應該更新網格過於自動,並且'#= formatMe(data)#'將被自動調用。 –