javascript - 剑道网格内联组合框不改变值
问题描述
我有带有内联版的 kendo mvc 网格。我想在网格中编辑我的值,但是当我单击组合框值并更改它时。它不会改变行值返回旧的现有值
我该如何解决这个问题?
这是我的网格和模板
@(Html.Kendo().Grid<MockUpForeNet.Controllers.CardDetailController.Limits>()
.Name("limitgrid").AutoBind(true)
.DataSource(dataBinding => dataBinding.Ajax()
.Read("GridLimitBinding", "CardDetail",new { rule = rule }).Update("UpdateLimit", "Transaction")
.Model(keys =>
{
keys.Id(c => c.Id);
keys.Field(c => c.Id).Editable(false);
keys.Field("DurationType", typeof(string)).Editable(true);
keys.Field("DurationValue", typeof(string)).Editable(true);
keys.Field("ValueType", typeof(string)).Editable(true);
keys.Field("MaxValue", typeof(string)).Editable(true);
}).Batch(true).ServerOperation(false)
)
.Events(e => e.DataBound("hidecolumn1"))
.Editable(editing => editing.Mode(Kendo.Mvc.UI.GridEditMode.InCell))
.ToolBar(commands =>
{
commands.Create().Text(" ");
commands.Save().SaveText(" ").CancelText(" ");
})
.Columns(columns =>
{
columns.Bound(e => e.MaxValue).Width(200).Title("Limit").ClientTemplate("#= ValueType == 'Amount' ? Row(MaxValue) : RowLiters(MaxValue) #");
columns.Bound(e => e.ValueType).Width(200).Title("Type").EditorTemplateName("ValueType");
columns.Bound(e => e.DurationValue).Width(200).Title("Duration");
columns.Bound(e => e.DurationType).Width(200).Title("Duration Type").EditorTemplateName("DurationType");
columns.Bound(e => e.Id).Visible(false);
columns.Bound(e => e.Id).Width(80).ClientTemplate("<img src='../../assets/images/icons/delete.svg' id='#=Id#' />").Filterable(false).IncludeInMenu(false).Title(" ");
})
//.Selectable()
.Sortable()
.Navigatable(configurator => configurator.Enabled(true))
///My template
@(Html.Kendo().ComboBox()
.Name("cbvaltype").ValuePrimitive(true)
.Items(i =>
{
i.Add().Text("Quantity").Value("Quantity");
i.Add().Text("Amount").Value("Amount");
})
)
解决方案
就个人而言,我会像这样在剑道中创建一个组合框:
组合框所在的列(这里没有任何变化):
columns.Bound(e => e.ValueType).Width(200).Title("Type").EditorTemplateName("ValueType");
模板:
@model // The model of the comboBox (Which as I have stated below should be `ValueType`)
@(Html.Kendo().ComboBoxFor(m => m)
.HtmlAttributes(new {data_skip = "true", data_bind = "defferedValue: ValueType"})
.PlaceHolder("Select a value")
.DataSource(source =>
{
source.Read("GetValues", "//Controller").ServerFiltering();
})
.MinLength(3)
.AutoBind(false)
.Filter(FilterType.Contains)
.DataValueField("ValueID")
.DataTextField("ValueText")
)
控制器:
public ActionResult GetValues(string text)
{
List<ValueModel> valueList = new List<ValueModel>();
if(!string.IsNullOrWhiteSpace(text)){
valueList = //Get a list of values which you want to be in this list (ie what you want to show in the comboBox)
// Above you should also do some LINQ to query against the list and get the correct values (ie .Where(x => x.ToLower().Contains(text.ToLower())).ToList())
}
return Json(valueList, JsonRequestBehaviour.AllowGet)
}
那么,我们在上面做什么呢?
我已将模板更改为接受模型类,并且我们已将组合框从 ComboBox 编辑为 ComboBoxFor。这使用传递到视图中的模型。
.DataValueField("ValueID")
.DataTextField("ValueText")
本质上是comboxBox的ID和文本。
注意:我相信,如果还没有,您应该将ValueType
变量更改为一个名为的类ValueType
或其他类,并且该类应该定义如下:
public class ValueType
{
public int ValueID{get;set;}
public string ValueText{get;set;}
}
MinLength(3)
指定用户至少需要键入 3 个字符才能开始组合框搜索。
我们调用一个GetValues
接受参数的控制器方法,text
在这里我们检查以确保text
它不是 null 或空,然后从ValueType
Valuetext ToLower() 包含传递给函数的文本的列表中返回值。
然后我们将它返回给模板,然后在网格中设置值。
推荐阅读
- cassandra - 将来如何删除带有时间戳的墓碑
- java - Spring boot/Spring data jpa - 如何更新相关实体?
- javascript - 获取从 blob URL 生成的黑色图像
- c# - 将 gridview 导出到 Excel 时遇到问题
- python - Python从日期时间索引计算每天的小时数
- python - Wx.stc.StyledTextCtrl 滚动条
- python - Errno 2 没有这样的文件或目录:'ffprobe':'ffprobe'
- c# - C# 中的语句之间是否存在延迟?
- firebase - 在 gunicorn 上的 Flask 中使用 eventlet 和 Firebase 时,关键工作人员超时
- ios - 自己的警报控制器