Aakash N

Aakash N

  • NA
  • 166
  • 19.5k

Cascading kendo dropdownlist => kendo dropdowntree

Oct 17 2018 1:12 PM
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
  1. <label class="nav-label">Supplier</label>  
  2. <div>  
  3. @(Html.Kendo().DropDownList()  
  4. .Name("supplier-dropdown")  
  5. .DataTextField("SupplierOrganizationName")  
  6. .DataValueField("MasterId")  
  7. .ValueTemplate("<text><span>#: data.MasterId #</span> - <span>#: data.SupplierOrganizationName #</span></text>")  
  8. .Template("<text><span>#: data.MasterId #</span> - <span>#: data.SupplierOrganizationName #</span></text>")  
  9. .Events(e =>  
  10. {  
  11. e.Change("onSupplierSelect");  
  12. })  
  13. .DataSource(source =>  
  14. {  
  15. source.Read(read =>  
  16. {  
  17. read.Action("GetSuppliers""Home");  
  18. });  
  19. }).OptionLabel("Select Supplier...").HtmlAttributes(new { @class = "nav-supplier-dropdown" }))  
  20. </div>  
onSupplierSelect event loads data to dropdowntree
  1. var masterId = '';  
  2. function onSupplierSelect(e) {  
  3. masterId = $('#supplier-dropdown').val();  
  4. var url = '@Url.Action("GetDivisionLocation", "Home")' + '/' + masterId;  
  5. $.get(url, function (response) {  
  6. var dropdowntree = $("#dropdowntree").data("kendoDropDownTree");  
  7. dropdowntree.dataSource(response);  
  8. });  
  9. }  
  10. function additionalInfo() {  
  11. return {  
  12. masterId: masterId  
  13. }  
  14. }  
dropdowntree htmlHelper tag
  1. $(document).ready(function () {  
  2. // create kendoDropDownTree from input HTML element  
  3. $("#dropdowntree").kendoDropDownTree({  
  4. placeholder: "Select Divisions/ Locations...",  
  5. //template: kendo.template($("#dropdowntree-template").html()),  
  6. //valueTemplate: kendo.template($("#dropdowntree-value-template").html()),  
  7. autoWidth: true,  
  8. height: "auto",  
  9. checkboxes: {  
  10. checkChildren: true  
  11. },  
  12. filter: "startswith",  
  13. checkAll: true,  
  14. autoClose: false,  
  15. //dataSource: response,  
  16. //dataTextField: ["divName", "locName"],  
  17. //dataValueField: "divId"  
  18. });  
  19. });  
controller method which loads data
  1. public JsonResult GetDivisionLocation(String id)  
  2. {  
  3. List<RootObject> rootObjects = new List<RootObject>();  
  4. List<DivisionsLocationOption> divisionLocationOptions = this._supplierService.GetDivisionLocationCollections("507981", id);  
  5. var data = (from m in divisionLocationOptions  
  6. select m.masterId).Distinct();  
  7. foreach (var itemTop in data)  
  8. {  
  9. var data1 = divisionLocationOptions.FirstOrDefault(cond => cond.masterId == itemTop);  
  10. RootObject rootObject = new RootObject  
  11. {  
  12. text = data1.parkerDivName,  
  13. expanded = false,  
  14. checkAll = false  
  15. };  
  16. var data2 = divisionLocationOptions.Where(cond => cond.masterId == itemTop);  
  17. List<Item> items = new List<Item>();  
  18. foreach (var item in data2)  
  19. {  
  20. items.Add(new Item  
  21. {  
  22. text = item.parkerLocName  
  23. });  
  24. }  
  25. rootObject.items = items;  
  26. rootObjects.Add(rootObject);  
  27. }  
  28. return Json(rootObjects);  
  29. }  
Here, I want to load dropdowntree with nodes and its own children

Answers (1)