修改
主要问题已得到解答(在kendo.ToString(value, format)
内使用ClientTemplate(string)
。以下问题仍未解决:
如果单元格没有内容(=空字符串)并且其行中的某些值已被编辑,则它会在更新事件期间显示null
。如何暂停?
修改结束
使用KendoUI Grid(来自Telerik)和ASP.NET MVC包装器,我有一些(对我来说)关于可编辑单元格的无法解释的行为。
由于我们的网格需要填充不同类型的数据,因此绑定模型对所有列使用类型string
,并通过显式定义选择编辑器模板。没有元数据绑定到关于可在模型中编辑的字段,因为可能每个列都可以编辑。不可编辑的单元格只需在编辑事件的处理程序中调用this.closeCell()
。
使用Kendo DatePicker:
DatePicker配置为使用德语样式的日期格式.Format("dd.MM.yyyy").Culture("de-DE")
。 DatePicker是德语,显示的日期仍然在单元格内,使用定义的格式
这很好:
只要我在单元格外单击,格式就会切换为英文长格式:
通过数据源的更新功能发送到我的后端的值有第三种格式:
任何人都可以向我解释,在所有三种情况下我如何能够像第一种情况一样使用德国日期(即" 10.03.2015")?
另一件事:
如果单元格没有内容(=空字符串)并且其行中的某些值已被编辑,则它会在更新事件期间显示null
。如何暂停?
其他信息:
kendo.culture("de-DE");
kendo.culture.de-DE.min.js
已包含在内。<globalization uiCulture="de-DE" culture="de-DE"/>
部分中的<system.web>
。代码:
视图中网格的相关部分:
@(Html.Kendo().Grid<SubfileModel>()
.Name("SubfileGrid")
.Columns(columns =>
{
Dictionary<string, string> alignment = new Dictionary<string, string>();
alignment.Add("", "left");
alignment.Add(" ", "left");
alignment.Add("L", "left");
alignment.Add("Z", "center");
alignment.Add("C", "center");
alignment.Add("R", "right");
for (int i = 0; i < 20; i++)
{
if (Model.GridMeta.columns.Count >= i && Model.GridMeta.columns[i].Header != "")
{
columns.Bound(p => p.Fields[i].Content)
.HtmlAttributes(new { style = "text-align:" + alignment[Model.GridMeta.columns[i].Alignment], @class = (Model.GridMeta.columns[i].Monospaced ? "monospace" : "") + (Model.GridMeta.columns[i].Uppercase ? " uppercase" : "") })
.HeaderHtmlAttributes(new { style = "text-align:" + alignment[Model.GridMeta.columns[i].Alignment], @class = (Model.GridMeta.columns[i].Monospaced ? "monospace" : "") + (Model.GridMeta.columns[i].Uppercase ? " uppercase" : "") })
.ClientTemplate("#= fillContentTemplate(Fields[" + i + "].Color, Fields[" + i + "].Image, Fields[" + i + "].Content, Fields[" + i + "].Error)#")
.EditorTemplateName("SubfileEditor" + Model.GridMeta.columns[i].Type)
.FooterTemplate("<div class='gridFooter' style='text-align:" + alignment[Model.GridMeta.columns[i].Alignment] + "'>" + Model.GridMeta.columns[i].Footer + "</div>")
.EditorViewData(new { length = Model.GridMeta.columns[i].Length, negative = Model.GridMeta.columns[i].Negative, matchcodes = Model.GridMeta.columns[i].Matchcode, number = i.ToString() })
.Title(Model.GridMeta.columns[i].Header)
.Width(Math.Max(Model.GridMeta.columns[i].Header.Length * 12 + 40, Convert.ToInt32(Model.GridMeta.columns[i].Length.Substring(0, Model.GridMeta.columns[i].Length.IndexOf(","))) * 12));
}
}
})
.Editable(e => e.Mode(GridEditMode.InCell).Enabled(Model.GridMeta.editable))
.Selectable(e => e.Mode(GridSelectionMode.Single).Type(GridSelectionType.Cell)) )
使用的模型:
public class SubfileModel2 //Overall Model to the View
{
public GridMeta GridMeta { get; set; }
public DetailsFields[,] WindowContent { get; set; }
}
public class GridMeta //Metainformation of the Grid
{
public List<ColumnMeta> columns { get; set; }
public bool editable { get; set; }
public bool footerUsed { get; set; }
}
public class ColumnMeta //Metainformation of the Columns
{
public string Header { get; set; }
public string Alignment { get; set; }
public string Type { get; set; }
public bool Monospaced { get; set; }
public bool Uppercase { get; set; }
public string Length { get; set; }
public bool Negative { get; set; }
public List<SelectListItem> Matchcode { get; set; }
public string Footer { get; set; }
}
public class SubfileModel //Content (Rows) of the Grid
{
public string Table { get; set; }
public string Program { get; set; }
public bool IsSelected { get; set; }
public int RRN { get; set; }
public int errorRRN { get; set; }
public string NonSelectable { get; set; }
public string BackgroundColor { get; set; }
public List<FieldInformation> Fields { get; set; }
}
public class FieldInformation //Cells of a Row
{
public string Content { get; set; }
public string Type { get; set; }
public string Type2 { get; set; }
public string Length { get; set; }
public string Align { get; set; }
public string Image { get; set; }
public string IsNegative { get; set; }
public string Color { get; set; }
public bool Error { get; set; }
public bool Editable { get; set; }
public string SQLQuery { get; set; }
}
有问题的EditorTemplate:
@model string
@(Html.Kendo().DatePicker()
.Name("Fields_" + (string)ViewData["number"] + "__Content")
.HtmlAttributes(new { name = "Fields[" + (string)ViewData["number"] + "].Content", data_bind = "value:Fields[" + (string)ViewData["number"] + "].Content" })
.Format("dd.MM.yyyy")
.Culture("de-DE")
)