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
- <label class="nav-label">Supplier</label>
- <div>
- @(Html.Kendo().DropDownList()
- .Name("supplier-dropdown")
- .DataTextField("SupplierOrganizationName")
- .DataValueField("MasterId")
- .ValueTemplate("<text><span>#: data.MasterId #</span> - <span>#: data.SupplierOrganizationName #</span></text>")
- .Template("<text><span>#: data.MasterId #</span> - <span>#: data.SupplierOrganizationName #</span></text>")
- .Events(e =>
- {
- e.Change("onSupplierSelect");
- })
- .DataSource(source =>
- {
- source.Read(read =>
- {
- read.Action("GetSuppliers", "Home");
- });
- }).OptionLabel("Select Supplier...").HtmlAttributes(new { @class = "nav-supplier-dropdown" }))
- </div>
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 () {
-
- $("#dropdowntree").kendoDropDownTree({
- placeholder: "Select Divisions/ Locations...",
-
-
- autoWidth: true,
- height: "auto",
- checkboxes: {
- checkChildren: true
- },
- filter: "startswith",
- checkAll: true,
- autoClose: false,
-
-
-
- });
- });
controller method which loads data
- public JsonResult GetDivisionLocation(String id)
- {
- List<RootObject> rootObjects = new List<RootObject>();
- List<DivisionsLocationOption> 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<Item> items = new List<Item>();
- 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