无法在 kendo 网格中显示颜色选择器选择的颜色
Impossible to display the color choosen by color picker in kendo grid
我有一个带颜色选择器的网格,当我从调色板中选择颜色时,我会显示十六进制颜色代码,而不是状态列中的颜色。
这是我称为 QTPStatusEditor 的模板编辑器:
@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;'> </div>"
); 添加到:
columns.Bound(o => o.Status).EditorTemplateName("QTPStatusEditor").Title("Status").ClientTemplate("<div style='background-color: #=Status#;padding:10px;'> </div>");
但是当我这样做时,我得到一个 javascript 错误:Uncaught ReferenceError : Status is not defined
您也可以在附件中看到。该线不再显示在网格中。
提前感谢您的帮助
此致,
这是 Kendo 管理员的解决方案:
确实,在当前情况下使用客户端模板是正确的方法。由于当前 Grid 本身位于客户端模板中,因此应转义作为模板一部分的哈希符号。
.ClientTemplate("<div style='background-color: \#=Status\#;padding:10px;'> </div>");
我有一个带颜色选择器的网格,当我从调色板中选择颜色时,我会显示十六进制颜色代码,而不是状态列中的颜色。
这是我称为 QTPStatusEditor 的模板编辑器:
@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;'> </div>"
); 添加到:
columns.Bound(o => o.Status).EditorTemplateName("QTPStatusEditor").Title("Status").ClientTemplate("<div style='background-color: #=Status#;padding:10px;'> </div>");
但是当我这样做时,我得到一个 javascript 错误:Uncaught ReferenceError : Status is not defined 您也可以在附件中看到。该线不再显示在网格中。
此致,
这是 Kendo 管理员的解决方案:
确实,在当前情况下使用客户端模板是正确的方法。由于当前 Grid 本身位于客户端模板中,因此应转义作为模板一部分的哈希符号。
.ClientTemplate("<div style='background-color: \#=Status\#;padding:10px;'> </div>");