Kendo Grid Inline组合框不会更改值

时间:2020-02-26 10:14:50

标签: javascript asp.net-mvc kendo-ui kendo-grid kendo-asp.net-mvc

我有带有内嵌版的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");
                })
            )

1 个答案:

答案 0 :(得分:0)

我个人将在剑道中创建一个comboBox,如下所示:

comboBox框所在的列(此处未更改):

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从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个字符才能开始comboBox搜索。

我们调用控制器方法GetValues,该方法接受参数text,在此我们检查以确保text不为null或为空,然后从{的列表中返回值{1}}是Valuetext ToLower()包含传递给函数的文本的地方。

然后将其返回到模板,该模板随后在网格中设置值。

相关问题