This is a migrated thread and some comments may be shown as answers.

ComboBox selection not sticking when leaving edited column

1 Answer 57 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Robert
Top achievements
Rank 1
Robert asked on 07 Dec 2016, 10:33 PM

I have a grid that is sourced by a List of Objects within my model (local binding).  I need to have the editor for the Name column (the only column in the grid) to be a ComboxBox where they can choose from a specified list.  I got that part working, however, whenever I leave the combobox, it sets the column to the default value for the name field instead of the chosen item from the combobox.  I can not figure out what I am doing wrong.

Here is my grid:

@(Html.Kendo().Grid(Model.Locations)
    .Name("LocationsGrid")
    .ToolBar(toolbar => { toolbar.Create().Text("Add Location"); })
    .HtmlAttributes(new { style = "height: 150px;" })
    .Columns(columns =>
    {
        columns.Bound(l => l.Name);
        columns.Command(cmd => cmd.Destroy().Text("<i class='fa fa-trash-o'></i>")).Width(50);
    })
    .Scrollable()
    .Editable(editable => editable.Mode(GridEditMode.InCell).DisplayDeleteConfirmation(false))
    .DataSource(ds =>
        ds.Ajax()
        .Batch(true)
        .ServerOperation(false)
        .Model(model => { model.Id(p => p.Id); model.Field(l => l.Name).DefaultValue("Select a Location"); })
            .Create(create => create.Action("AddLocationToProcess", "ProjectConfiguration"))
            .Destroy(destroy => destroy.Action("RemoveLocationFromProcess", "ProjectConfiguration"))
        )
        .Events(events => events.Edit("LocationsGrid_edit"))
    )

 

Here is my Editor:

@model int?
@(Html.Kendo().ComboBoxFor(model => model)
    .Name("SweepTriggeredLocationCB_" + new Random().Next())
    .DataTextField("Name")
    .DataValueField("Id")
    .Placeholder("Select Location...")
    .Suggest(true)
    .Filter(FilterType.StartsWith)
    .DataSource(ds =>
    {
        ds.Read(read => read.Action("GetAddProcessLocations", "ProjectConfiguration").Data("GetAddLocationData"));
    })
    .Value(Model.HasValue ? Model.Value.ToString() : null)
    .Events(events => events.Change("StandardComboBox_change"))
)

 

Here is the portion of my Model showing the UIHint for the Editor:

[Required(ErrorMessage = "{0} is required.")]
[NoWhiteSpace(ErrorMessage = "{0} cannot begin or end with a space.")]
[UIHint("SweepTriggeredLocationEditor")]
public string Name { get; set; }

1 Answer, 1 is accepted

Sort by
0
Konstantin Dikov
Telerik team
answered on 09 Dec 2016, 03:13 PM
Hi Robert,

There are few issues with your configuration: 
  • The Name of the ComboBox should match exactly the name of the field;
  • The template should accept string value and not int, because from what I see in the model, the Name property is of string type;
  • The DataValueField of the ComboBox should point to "Name" as well, because you are passing that name only

Please test the above changes and see if the issue is resolved.


Regards,
Konstantin Dikov
Telerik by Progress
Telerik UI for ASP.NET MVC is ready for Visual Studio 2017 RC! Learn more.
Tags
Grid
Asked by
Robert
Top achievements
Rank 1
Answers by
Konstantin Dikov
Telerik team
Share this question
or