2017-08-22 109 views
0

我在ASP.NET MVC中使用kendo網格,我想將某些顏色規則應用於某些列的單元格。 爲此我嘗試了HtmlAttributes(使用類似乎是最簡單的方法)和ClientTemplate,但兩者都不起作用。 此外,我根據ViewModel中的變量創建了許多列。同時使用Template和ClientTemplate作爲Kendo Grid列

我正要宣佈一個布爾值的選項卡,意思是每個列必須是可見的(以便它看起來似乎是靜態的)。我無法動態使用columns.Bound(),但是我可以在for循環中動態添加columns.Template()的列。

Html.Kendo().Grid<ViewModelPilotageRetroPlanningOpeDetail>() //Bind the grid to ViewBag.Products 
     .Name("pilotageRetroPlanningListeOpesDivabc") 
     .BindTo(Model.ListeOpes) 
     .Columns(columns => 
     { 
      columns.Bound(ope => ope.NbTachesRetard).Title("Nb tâches en retard").Template(@<text> @if (item.NbTachesRetard != 0) 
      { 
       <span class="retards"> @item.NbTachesRetard </span> 
      } 
      else 
      { 
       <span class="pasDeRetards"> @item.NbTachesRetard </span> 
      } 
      </text>); 


      for (int i = 0; i < Model.NombreJalonsUtilises; i++) 
      { 
      var index = i; 
      columns.Template(@<text> @item.ListeStatutJalon.ElementAt(index).ToString() </text>).Title("J" + (i + 1).ToString()).Width(25); 
      } 
     } 

它的工作原理和顯示的列通緝enter image description here

現在我需要顯示的圖像,而不是數字,我會需要使用ClientTemplate細胞聯想到的img標籤

我問題是: 是否可以使用Template和ClientTemplate來添加基於@ item.ListeStatutJalon.ElementAt(index)給出的值的類? 因爲當我添加ClientTemplate時,模板的值沒有出現在單元格中。

回答