Kendo Grid Inline组合框不会更改值 [英] Kendo Grid Inline combobox not changing value

查看:66
本文介绍了Kendo Grid Inline组合框不会更改值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有带有内嵌版的kendo mvc网格.我想在网格中编辑我的值,但是当我单击组合框值并更改它时.它不是在更改行值,而是返回旧的现有值

I have kendo mvc grid with inline edition. I want to edit my values in grid but when i click on combobox value and change it. It's not changing row value return old existing value

我该如何解决?

这是我的网格和模板

    @(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");
                })
            )

推荐答案

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

Personally, I would create a comboBox in kendo like this:

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

The column in which the comboBox box is located (Nothing has changed here):

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)
}

那么,我们在上面做什么?

So, what are we doing above?

我已更改模板以接受模型类,并且我们已将comboBox从ComboBox修改为ComboBoxFor.这将使用传递给视图的模型.

I have changed the template to accept a model class and we have edited the comboBox from a ComboBox to a ComboBoxFor. This uses the model passed into the view.

        .DataValueField("ValueID")
        .DataTextField("ValueText")

本质上是comboxBox的ID和文本.

Are essentially the ID and text of the comboxBox.

注意:我相信,如果尚未将ValueType变量更改为称为ValueType的类,则应定义该类,如下所示:

NOTE: I believe, if not already, you should change ValueType variable to be a class called ValueType or whatever and that class should be define such as the following:

public class ValueType
{
    public int ValueID{get;set;}
    public string ValueText{get;set;}
}

MinLength(3)指定用户至少需要键入3个字符才能开始comboBox搜索.

MinLength(3) specifies that the user needs to type a minimum of 3 characters to start the comboBox search.

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

We call a controller method GetValues which accepts the parameter text and in here we check to make sure text is not null or empty and then return the values from a list of ValueType's where the Valuetext ToLower() contains the text passed into the function.

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

We then return that to the template which then sets the value in the grid.

这篇关于Kendo Grid Inline组合框不会更改值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆