I am using Kendo UI for asp.net core, presently I'm trying to load the values of kendo dropdowntree based on kendo dropdownlist selected value. The aim is to load dropdowntree with its child nodes. But, only the first parent node with all the children are loaded (node1 appends all other children from other nodes2,3)
Cascades from dropdownlist
- @(Html.Kendo().DropDownList()
- .Name("supplier-dropdown")
- .DataTextField("SupplierOrganizationName")
- .DataValueField("MasterId")
- .ValueTemplate("
#: data.MasterId # - #: data.SupplierOrganizationName # ")- .Template("
#: data.MasterId # - #: data.SupplierOrganizationName # ")- .Events(e =>
- {
- e.Change("onSupplierSelect");
- })
- .DataSource(source =>
- {
- source.Read(read =>
- {
- read.Action("GetSuppliers", "Home");
- });
- }).OptionLabel("Select Supplier...").HtmlAttributes(new { @class = "nav-supplier-dropdown" }))
onSupplierSelect event loads data to dropdowntree
- var masterId = '';
- function onSupplierSelect(e) {
- masterId = $('#supplier-dropdown').val();
- var url = '@Url.Action("GetDivisionLocation", "Home")' + '/' + masterId;
- $.get(url, function (response) {
- var dropdowntree = $("#dropdowntree").data("kendoDropDownTree");
- dropdowntree.dataSource(response);
- });
- }
- function additionalInfo() {
- return {
- masterId: masterId
- }
- }
dropdowntree htmlHelper tag
- $(document).ready(function () {
- // create kendoDropDownTree from input HTML element
- $("#dropdowntree").kendoDropDownTree({
- placeholder: "Select Divisions/ Locations...",
- //template: kendo.template($("#dropdowntree-template").html()),
- //valueTemplate: kendo.template($("#dropdowntree-value-template").html()),
- autoWidth: true,
- height: "auto",
- checkboxes: {
- checkChildren: true
- },
- filter: "startswith",
- checkAll: true,
- autoClose: false,
- //dataSource: response,
- //dataTextField: ["divName", "locName"],
- //dataValueField: "divId"
- });
- });
controller method which loads data
- public JsonResult GetDivisionLocation(String id)
- {
- List
rootObjects = new List (); - List
divisionLocationOptions = this._supplierService.GetDivisionLocationCollections("507981", id); - var data = (from m in divisionLocationOptions
- select m.masterId).Distinct();
- foreach (var itemTop in data)
- {
- var data1 = divisionLocationOptions.FirstOrDefault(cond => cond.masterId == itemTop);
- RootObject rootObject = new RootObject
- {
- text = data1.parkerDivName,
- expanded = false,
- checkAll = false
- };
- var data2 = divisionLocationOptions.Where(cond => cond.masterId == itemTop);
- List
- items = new List
- ();
- items = new List
- foreach (var item in data2)
- {
- items.Add(new Item
- {
- text = item.parkerLocName
- });
- }
- rootObject.items = items;
- rootObjects.Add(rootObject);
- }
- return Json(rootObjects);
- }
Here, I want to load dropdowntree with nodes and its own children

Vincent Maverick DuranoPosted Oct 17, 2018, 4:59 PM