Kendo Grid Inline combobox not changing value

自闭症网瘾萝莉.ら 提交于 2021-02-11 14:49:53

问题


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

How can i solve this?

Here my grid and Template

    @(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:


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

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

columns.Bound(e => e.ValueType).Width(200).Title("Type").EditorTemplateName("ValueType");

The template:

@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")
        )

Controller:

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?

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

Are essentially the ID and text of the comboxBox.

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) specifies that the user needs to type a minimum of 3 characters to start the comboBox search.

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.



来源:https://stackoverflow.com/questions/60411526/kendo-grid-inline-combobox-not-changing-value

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!