1

我有一个带有颜色选择器的网格,当我从调色板中选择颜色时,我会显示十六进制颜色代码,而不是状态列中的颜色。

在状态列中显示十六进制代码而不是颜色 在此处输入图像描述

这是我称为 QTPStatusEditor 的 TemplateEditor:

@model string 
@(Html.Kendo().ColorPickerFor(m=>m)
        .Name("Status")
      .Palette(new[] { "rgba(255, 255, 255, 1)", "rgba(0, 204, 0, 1)", "rgba(255, 51, 51, 1)", "rgba(255, 201, 14, 1)" })
      .Columns(4)
      )

这是我的网格:

@(Html.Kendo().Grid<Volvo.Qarma.MVCWebUIComponent.Models.Views.ProposedQToolViewModel>()
              .Name("QTPGridItems_#=Id#")
               .ToolBar(toolbar => toolbar.Template(@<text>
                <div class="toolbar">
                   <input type="button" id="SaveProposedQTools" class="icon save k-grid-save-changes" value="@ScreeningResource.Screening_TreatmentPlan_SaveProposedQTools" />
                </div>
            </text>))
              .Columns(columns =>
              {
                  columns.Bound(o => o.RefQTool.Name).Title("Pro-active actions");
                  columns.Bound(o => o.Responsable).Title("Responsible");
                  columns.Bound(o => o.QtoolLeader).Title("Qtool Leader");
                  columns.Bound(o => o.Location.LongName).EditorTemplateName("LocationListEditor").Title("Location");

                  columns.Bound(o => o.Status).EditorTemplateName("QTPStatusEditor").Title("Status");

                  columns.Bound(o => o.PlannedStartDate).EditorTemplateName("PlannedStartDateEditor").Title("Planned start date").Format("{0:dd/MM/yyyy}");
                  columns.Bound(o => o.PlannedEndDate).EditorTemplateName("PlannedEndDateEditor").Title("Planned End date").Format("{0:dd/MM/yyyy}");
                  columns.Bound(o => o.LastUpdateDate).EditorTemplateName("LastUpdateDateEditor").Title("Last Update Date").Format("{0:dd/MM/yyyy}");
                  columns.Bound(o => o.LinkToDocument).Title("Link To Document");
                  columns.Bound(o => o.Comment).Title("Comment");
              })
              .DataSource(dataSource => dataSource
                  .Ajax()
                  .Batch(true)
                  .ServerOperation(false)
                  .PageSize(10)
                  .Read(read => read.Action("QtpGridSelectedQtools", "QTP", new { itemId = "#=Id#" })
                   .Data("function() { return getCommodityID('QTPGridItems_#=Id#');}"))
                   .Create(create => create.Action("Create_TreatmentPlan", "Screening", new { itemId = "#=Id#" }))
                   .Update(update => update.Action("Update_TreatmentPlan", "Screening", new { itemId = "#=Id#" }))
                  .Model(model =>
                  {
                      model.Id(p => p.Id);
                      model.Field(p => p.Id).Editable(false);
                      model.Field(p => p.RefQTool.Name).Editable(false);
                      model.Field(p => p.Responsable).Editable(true);
                      model.Field(p => p.QtoolLeader).Editable(true);
                      model.Field(p => p.Location).Editable(true).DefaultValue(ViewData["defaultLocation"] as LocationsViewModel);
                      model.Field(p => p.PlannedStartDate).Editable(true);
                      model.Field(p => p.PlannedEndDate).Editable(true);
                      model.Field(p => p.LastUpdateDate).Editable(true);

                      model.Field(p => p.Status);

                  })
              )

              .Selectable()
              .Pageable()
              .Sortable()
              .Editable(editable => editable.Mode(GridEditMode.InCell))

              .ToClientTemplate()

        )

我在一些示例中看到我需要添加 .ClientTemplate(" <div style='background-color: #=Status#;padding:10px;'>&nbsp;</div>"); 到:

columns.Bound(o => o.Status).EditorTemplateName("QTPStatusEditor").Title("Status").ClientTemplate("<div style='background-color: #=Status#;padding:10px;'> </div>");

但是当我这样做时,我得到一个 javascript 错误: 未捕获的ReferenceError:未定义状态 ,您也可以在附件中看到。并且该行不再显示在网格中。

错误 提前感谢您的帮助

问候,

4

1 回答 1

1

这是剑道管理员的解决方案:

实际上,在当前场景中使用客户端模板是正确的方法。由于当前 Grid 位于客户端模板本身中,因此应转义作为模板一部分的哈希符号。

.ClientTemplate("<div style='background-color: \\#=Status\\#;padding:10px;'> </div>");
于 2016-02-01T09:25:13.893 回答