2016-09-25 69 views
0

我想訪問的數據排在劍道UI格列命令模板,但沒有找到解決方案來解決這一請求。如何訪問kendo ui網格列命令模板中的數據行?

<script> 
 
$("#grid").kendoGrid({ 
 
    columns : [{ 
 
      field : "firstname", 
 
      title : "First Name" 
 
     }, { 
 
      field : "lastname", 
 
      title : "Last Name" 
 
     }, { 
 
      field : "cellphone", 
 
      title : "Cell Phone" 
 
     }, { 
 
      field : "deskphone", 
 
      title : "Desk Phone" 
 
     }, { 
 
      field : "emailaddress", 
 
      title : "Email Address" 
 
     }, 
 
     { 
 
      command : [ 
 
      { 
 
       name: "note", 
 
       text: "note", 
 
       template:"<a class='tds-grid-button k-button k-grid-#: name #' title='#: text #'> #: rowData.ID # <i class='fa fa-comment-o'></i></a>", 
 
       imageClass: "fa fa-comment-o", 
 
       click: note_Clicked 
 
      } 
 
] 
 
}); 
 
</script>

我想從行的數據訪問ID值列命令模板:#: rowData.ID #

template:"<a class='tds-grid-button k-button k-grid-#: name #' title='#: text #'> #: rowData.ID # <i class='fa fa-comment-o'></i></a>" 

如何解決這個解決方案?

回答

0

我不認爲你可以做到這一點,你現在的樣子。我認爲你不能以這種方式訪問​​行數據。 如果你有一個函數調用,而不是取代你的rowData.ID,該功能只執行了兩次,一次,每行渲染,這意味着網格初始化過程中只有「執行」的模板。

我發現這個論壇Telerik的職位,談到這一點:http://www.telerik.com/forums/accessing-row-data-in-a-command 凡建議您使用網格的數據綁定事件改變按鈕上的文字,他們提供了一個鏈接到一個演示道場。

這裏是一個演示,我把從論壇帖子的道場,並稍加修改數據綁定處理程序使用該ID從DataItem的動態改變按鈕上的文本的鏈接。 http://dojo.telerik.com/@Stephen/oVuCo

我不知道怎麼回事做到這一點。

0

試試這個

$("#grid").kendoGrid({ 
dataSource: { 
    data: data, 
    schema: { 
    model: { 
     id: "Id", 
     fields:{ 
      Id: {type: "number"}, 
      firstname: { type: "string"}, 
      lastname: { type: "string"}, 
      cellphone: { type: "string"}, 
      deskphone: { type: "string"}, 
      emailaddress: { type: "string"} 
      } 
     } 
    } 
}, 
     columns : [{ 
       field : "firstname", 
       title : "First Name" 
      }, { 
       field : "lastname", 
       title : "Last Name" 
      }, { 
       field : "cellphone", 
       title : "Cell Phone" 
      }, { 
       field : "deskphone", 
       title : "Desk Phone" 
      }, { 
       field : "emailaddress", 
       title : "Email Address" 
      }, 
      { 
       command : [ 
       { 
        name: "note", 
        text: "note", 
        template: "<a class='tds-grid-button k-button k-grid-#=name#' title='#=name#'> 
    #=Id# <i class='fa fa-comment-o'></i></a>" 
       } 
    ] 
    }); 
    </script> 

注意 - 代替#=編號把你想在劍道網格設置主域。 我認爲你有在劍道網格數據源的模型。

0

坦克, 我發現我的解決方案來解決它。

可以使用劍道UI電網的數據綁定事件如下:

$("#grid").kendoGrid({ 
 
    columns : [{ 
 
      field : "firstname", 
 
      title : "First Name" 
 
     }, { 
 
      field : "lastname", 
 
      title : "Last Name" 
 
     }, { 
 
      field : "cellphone", 
 
      title : "Cell Phone" 
 
     }, { 
 
      field : "deskphone", 
 
      title : "Desk Phone" 
 
     }, { 
 
      field : "emailaddress", 
 
      title : "Email Address" 
 
     }, 
 
     { 
 
      command : [ 
 
      { 
 
       name: "note", 
 
       text: "note", 
 
       template:"<a class='tds-grid-button k-button k-grid-#: name #' title='#: text #'> #: rowData.ID # <i class='fa fa-comment-o'></i></a>", 
 
       imageClass: "fa fa-comment-o", 
 
       click: note_Clicked 
 
      } 
 
], 
 
dataBound: function() { 
 
         var grid = this; 
 
         var model; 
 

 
         grid.tbody.find("tr[role='row']").each(function() { 
 
          rowData = grid.dataItem(this); 
 
          rowData.ID 
 
          rowData.Name 
 
          //and more and more 
 
      } 
 
} 
 
});