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

How to use a ajax populated dropdown with a kendo parameter in a kendo grid with batch editing

1 Answer 324 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Logan
Top achievements
Rank 1
Veteran
Logan asked on 19 Aug 2013, 08:38 PM

I have a Kendo grid that has a requirement for using a conditional dropdown in combination with batch editing. 

For instance I need to allow an order enterer set the color of a product from a dropdown, but each product has a potentially different set of available colors.

I have done something similar with InLine editing without a problem and the ajax call to populate the dropdown is getting called correctly in batch mode.  The problem appears to be that the #=productId# is not getting correctly parsed by Kendo.

View:

@( Html.Kendo().Grid<Web.Models.StudentGradeView>()
    .Name("Students")
    .Columns(columns =>
        {
            columns.Bound(c => c.Id);
            columns.Bound(c => c.Price);
            columns.Bound(c => c.Color);        })
        .ToolBar(toolbar =>
        {
            toolbar.Template( @"
                <span class=""pull-left"">
                        <a class=""btn k-grid-save-changes"" href=""javascript:void(0)""><span class=""k-icon k-update""></span> Save</a>
                        <a class=""btn k-grid-cancel-changes"" href=""javascript:void(0)""><span class=""k-icon k-cancel""></span> Cancel</a>
                </span>"
        })
        .Events(e => e.Edit("onEdit"))        .Editable(editable => editable.Mode(GridEditMode.InCell))
        .Sortable()
        .DataSource(dataSource => dataSource
            .Ajax()
            .Batch(true)
            .Events(events =>
                {
                    events.Error("error_handler");
                })
            .Model(model =>
                {
                    model.Id(m => m.Id);
                })
            .Read(read => read.Action("Product_Read", "Home", new { id = orderId }))
            .Update(update => update.Action("Product_Update", "Home"))
        )
    )

EditorTemplate

@model string

@(
 Html.Kendo().DropDownListFor(m => m)
    .OptionLabel("Select Color")
    .DataTextField("Color")
    .DataValueField("Color")
    .DataSource(dataSource =>
    {
        dataSource.Read("ColorsDropDown_Read", "DropDowns", new { Area = "", id = "#=ProductId#" });
    })
)


Controller

        public ActionResult ColorsDropDown_Read([DataSourceRequest] DataSourceRequest request, string id)
        {
            List<Grade> rVal = new List<Color>();
            rVal = _SystemSettings.AllColors.Where(w => w.ProductId == id)..ToList();         
            return Json(rVal, JsonRequestBehavior.AllowGet);
        }

Thanks!

 

1 Answer, 1 is accepted

Sort by
0
Accepted
Logan
Top achievements
Rank 1
Veteran
answered on 20 Aug 2013, 03:06 PM
Tags
Grid
Asked by
Logan
Top achievements
Rank 1
Veteran
Answers by
Logan
Top achievements
Rank 1
Veteran
Share this question
or