2013-10-23 78 views
0

我的問題與我的網格更新相關。這是我目前併網發電的計劃: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); 

所以,我在的情況下我的變量都不錯,但新線都沒有。

而不是破壞我的網格,並在更新數據後重建它們,你知道這種情況下的解決方案嗎?

非常感謝。

回答

1

這可能不完全是您的答案,但可以幫助您實現目標。每當網格的數據源更改時,formatMe函數將被調用,並且它的返回值將顯示在網格的單元格中。

function formatMe(data){ 
    return data + " bla bla"; 
} 

var grid = $("#grid").kendoGrid({ 
    dataSource: { 
     data: createRandomData(50) 
    }, 
    columns: [ 
     { field: "YourFieldName","template:"#= formatMe(data) #" }] 
}).data("kendoGrid"); 
+0

謝謝,我現在試試你的小費。我沒有想到在#=#中使用一個函數。 – jodu

+0

所以,當我在你建議的Columns字段中添加一個類時,它是可以的。 但是,當我想使用相同的過程來更正schema.model.fields.editable時,這並不好。我想我會直接使用data-role =「editable」... – jodu

+0

對不起,我現在太累了(編寫10Hrs的代碼)。我認爲你應該使用[數據源對象](http://docs.kendoui.c​​om/api/framework/datasource)並將其綁定到你的網格,然後每次你編輯或添加或從你的數據源中刪除它應該更新網格過於自動,並且'#= formatMe(data)#'將被自動調用。 –

0

最後,我發現了這個問題的替代解決方案。

變量「fige」是當我們選擇單元格時允許編輯的變量。 而不是使用KendoUi,我喜歡做我自己的解決方案。

當我建 「位置」 和 「longueur」 列:

{ 
    field : "position", 
    title : "Position", 
    width : 70, 
    template : "<span class='position#= index #' ><input style='width:70px' type='text' value='#= position#' #= readOnly(fige) # /></span>" 
},{ 
    field : "longueur", 
    title : "Longueur", 
    width : 70, 
    template : "<span class='longueur#= index #'><input style='width:70px' type='text' value='#= longueur#' #= readOnly(fige) # /></span>" 
} 

而且只讀(FIGE)功能:

function readOnly(fige) 
{ 
    if (fige == "true") 
     return "readonly"; 
    else 
     return ""; 
} 

動態,我獲得的細胞可編輯或不多虧了這個功能。也許它不如KendoUI默認的解決方案,但我不認爲這個特殊的功能是可能的,這要歸功於KendoUI。