2015-02-09 86 views
0

我正在使用劍道網格,它的工作正常。我需要檢查我的網格的每一行,如果它包含一個特定的值,然後使用一個模板綁定數據,否則模板將會不同。這可能嗎 ?這裏是我的代碼劍道網格,根據條件顯示不同的模板詳細網格

function detailInit(e) { 
     var isCreateGrid = true; 
     var masterRowId = e.data.uid; 
     var data = []; 
     $.ajax({ 
      type: "GET", 
      url: 'https://www.domain.com/details?&transactionId=' + e.data.TransactionId, 
      contentType: "application/json; charset=utf-8", 
      dataType: 'json', 
      headers: { 'ccode': compCode }, 
      cache: false, 
      async: false, 
      success: function (result) { 
       var jsonResult = JSON.parse(result); 
       for (var i = 0; i < jsonResult.length; i++) { 
        if (jsonResult[i]["OldValue"] == null || jsonResult[i]["OldValue"] == '') 
         isCreateGrid = true; 
        else { 
         isCreateGrid = false; 
         break; 
        } 
       } 
       if (isCreateGrid) { 
        for (var i = 0; i < jsonResult.length; i++) { 
         data.push({ FieldUpdated: jsonResult[i]["ChangeColumns"], Value: jsonResult[i]["NewValue"] }); 
        } 
       } else { 
        for (var i = 0; i < jsonResult.length; i++) { 
         data.push({ FieldUpdated: jsonResult[i]["ChangeColumns"], Was: jsonResult[i]["OldValue"], Now: jsonResult[i]["NewValue"] }); 
        } 
       } 
      } 
     }); 
     var dataSource = new kendo.data.DataSource({ data: data }); 
     if (data.length == 0) { 
      var grid = $("#logs").data("kendoGrid"); 
      grid.collapseRow("[data-uid='" + masterRowId + "']"); 
      grid.dataSource.read(); 
     } else { 
      if (isCreateGrid) { 
       $("<div/>").appendTo(e.detailCell).kendoGrid({ 
        dataSource: dataSource, 
        filter: { field: e.data.Log, operator: "contains", value: 'has created' }, 
        columns: 
         [{ field: "FieldUpdated", title: "Field Updated", width: "50px" }, 
         { field: "Value", title: "Value", width: "50px" }] 
       }); 
      } else { 
       $("<div/>").appendTo(e.detailCell).kendoGrid({ 
        dataSource: dataSource, 
        filter: { field: e.data.Log, operator: "contains", value: 'has created' }, 
        columns: 
         [{ field: "FieldUpdated", title: "Field Updated", width: "50px" }, 
         { field: "Was", title: "Was", width: "50px" }, 
         { field: "Now", title: "Now", width: "50px" }] 
       }); 

      } 
     } 
    } 

但這isCreateGrid條件似乎是無用的,因爲如果他發現任何行,其中isCreateGrid標準是錯誤的,那麼所有的行會針對錯誤的標準模板。

+0

您可以在網格的數據綁定事件中保持isCreateGrid的條件檢查 – 2015-02-09 08:54:52

回答

2

是的,你可以。請參閱下面的代碼。

$(gridId).kendoGrid({ 
    dataSource: { 
     data: datasource 
    }, 
    scrollable: true, 
    sortable: true, 
    resizable: true, 
    columns: [ 
    { field: "MetricName", title: "Metric", width: "130px" }, 
    { field: "OnTrack", title: "On Track", template:'#:changeTemplate(OnTrack)#', width: "130px", attributes: { style: "text-align: center !important;" } }, 
    { field: "CurrentAmount", title: "Current", template: '$ #:parseFloat(CurrentAmount).toFixed(2)#', width: "130px" }, 
    { field: "RequiredAmount", title: "Required", template: '$ #:parseFloat(RequiredAmount).toFixed(2)#', width: "130px" } 
    ] 
}); 

function changeTemplate(value) 
{ 
    Conditions depending on Your Business Logic 
if() 
    return "HTML Here"; 
else 
    return "HTML Here"; 
} 
+0

這是否適合您?那麼你可以投票嗎? – 2015-02-10 17:20:23