2017-08-22 113 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时,模板的值没有出现在单元格中。

回答