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

Grid column not binding on edit/ update

1 Answer 311 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Michael
Top achievements
Rank 1
Michael asked on 25 Oct 2018, 09:39 AM

Hi, 

My grid has a column called Merchant which is supposed to turn into a dropdown list on edit.

For some reason, The initial  selected value doesn't connect to the column- does not appear as selected. And when I save on update- The value of the merchant doesn't get the changes on server side- it stays with initial value!!!.

This is the grid:

            @(Html.Kendo().Grid<DefaultLimitViewModel>
            ()
            .Name("DefaultLimitsGrid")           
            .Columns(columns =>
            {
                 columns.Bound(o => o.Id).Hidden();
                columns.Bound(o => o.DateLimitId).Hidden();
                columns.Bound(o => o.Merchant.MerchantName).EditorTemplateName("MerchantEditor").Title("Merchant").Width(150);
                columns.Bound(o => o.Rail).EditorTemplateName("RailEditor").Title("Rail").Width(150);
                columns.Bound(o => o.DefaultAmount).Format("{0:c}");
                columns.Command(command => { command.Edit().CancelText(" ").UpdateText(" ").Text(" "); command.Destroy().Text(" "); }).Width(200);


            })
            .ToolBar(toolBar => toolBar.Create())
            .Sortable()
            .Pageable(x => { x.AlwaysVisible(false); })
            .Scrollable()
            .Editable(editable => editable.Mode(GridEditMode.InLine))         
            .HtmlAttributes(new { style = "height:600px;" })
            .DataSource(dataSource => dataSource
            .Ajax()
            .PageSize(8)
            .Read(read => read.Action("Get_LimitsDefaultData", "Limits"))
            .Update(update => update.Action("UpdateDefaultLimit", "Limits"))
            .Destroy(Delete => Delete.Action("DeleteDefaultLimit", "Limits"))
            .Create(Create => Create.Action("CreateNewDefaultLimit", "Limits"))
            .Model(
            model =>
            {
                model.Id(item => item.DateLimitId);
             
            })

            )      
            )
       

 

 

This is the MerchantEditor

@(Html.Kendo().DropDownList()
                    .Name("Merchant")
                    .DataValueField("MerchantId")
                    .DataTextField("MerchantName")
             .DataSource(d => d.Read("Merchants_Read", "Limits")))
   

this is the Merchans_Read function:

 public IActionResult Merchants_Read()
        {
           
            using (var db = Db.Open())
            {
                var merchants = db.Select<Merchant>().OrderBy(x => x.Name).Select(mm => new MerchantModel { MerchantId = mm.Id, MerchantName = mm.Name }).ToList();

                return Json(merchants);
            }

        }

 

 

 

1 Answer, 1 is accepted

Sort by
0
Viktor Tachev
Telerik team
answered on 29 Oct 2018, 08:23 AM
Hello Michael,

I have examined the code and noticed that the column was bound to the MerchantName field. However, the DropDownList editor is supposed to edit the Merchant field.

In order to have the editing work as expected I would suggest changing the column configuration so it is bound to Merchant. You can show the name in preview mode by using a ClientTemplate. The column configuration would look similar to the following:


columns.Bound(o => o.Merchant).ClientTemplate("#=Merchant.MerchantName#").EditorTemplateName("MerchantEditor").Title("Merchant").Width(150);


It is also recommended to specify default value for the Merchant column. It will be used when a new item is created. Check out the example below that illustrates how the Grid can be configured to use custom editor.



Regards,
Viktor Tachev
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
Grid
Asked by
Michael
Top achievements
Rank 1
Answers by
Viktor Tachev
Telerik team
Share this question
or