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

Dropdownlist with cascade and filter

1 Answer 969 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Xavier
Top achievements
Rank 1
Xavier asked on 01 Apr 2015, 08:08 AM
Hi guys,

It’s possible to make a control dropdownlist with settings cascade enabled and filtered by contains too. I show you the scenario:


Grid code

@(Html.Kendo().Grid<FareDetailViewModel>()
                            .Name("fare_details#=FareID#")
                            .ToolBar(t =>
                            {
                                if (User.IsInRole("Modify"))
                                {
                                    t.Create().Text("Afegir Referencia");
                                }
                            })
                            .Columns(columns =>
                            {
                                columns.ForeignKey(f => f.Tipus, (System.Collections.IEnumerable)ViewBag.CatalogTypes, "Key", "Value").EditorTemplateName("CustomGridForeignKeyFareType").Width(120);
                                //columns.ForeignKey(f => f.CatalogReference, (System.Collections.IEnumerable)ViewBag.Cataleg, "Reference", "Descripcio").EditorTemplateName("CatalegReferenceByType");
                                columns.Bound(f => f.CatalogReference).EditorTemplateName("CatalegReferenceByType").EditorViewData(new { gridid = "fare_details#=FareID#" });

Editor template

@model object
 
@(Html.Kendo().DropDownList()
    .Name("CatalogReference" + ViewData["gridid"])
    .HtmlAttributes(new { data_bind = "value:CatalogReference" })
    .AutoBind(false)
    .OptionLabel("Select reference...")
    .DataTextField("Descripcio")
    .DataValueField("Reference")
    .Filter(FilterType.Contains)
    .MinLength(3)
    .ValuePrimitive(true)
    //.HtmlAttributes(new { data_skip = "true", data_bind = "defferedValue: object" })
    //.BindTo((SelectList)ViewData[ViewData.TemplateInfo.GetFullHtmlFieldName("") + "_Data"])
    .DataSource(source =>
    {
        source.Read(read => read.Action("PopulateReferences", "Catalog").Data("filterTypes"))
            .ServerFiltering(true);
    })
    .CascadeFrom("Tipus")
    .HtmlAttributes(new { id = Guid.NewGuid().ToString() })
)

function filterTypes() {
            return {
                text: $("#Type").data("kendoDropDownList").value() + "|" + $("#CatalogReference" + temporalFare).data("kendoDropDownList").filterInput.val()
            };
        }


$("#CatalogReference" + temporalFare).data("kendoDropDownList") 
Here, I find the error.  Browser say me this expression is undefined

Controller Code

public JsonResult PopulateReferences(string text)
        {
            var param = text.Split('|');
            var type = (int)text[0];
            var search = text[1];
 
            var catalog = GetCatalog((catalogType)type).Where(c => (c.Descripcio + " " + c.Reference).Contains(search)).Select(c => new { Reference = c.Reference, Descripcio = c.Descripcio + " - " + c.Reference }).AsQueryable();
 
            return Json(catalog, JsonRequestBehavior.AllowGet);
        }

I hope this is helpful code.

 

 

Thanks in advance.



Xavier.




1 Answer, 1 is accepted

Sort by
0
Alexander Popov
Telerik team
answered on 06 Apr 2015, 06:17 AM
Hello Xavier,

I already answered in the other thread you posted, so I am closing this one.

Regards,
Alexander Popov
Telerik
 

See What's Next in App Development. Register for TelerikNEXT.

 
Tags
Grid
Asked by
Xavier
Top achievements
Rank 1
Answers by
Alexander Popov
Telerik team
Share this question
or