Do you have an example of how the current value is supposed to be set?

When I use the DropDownTree control and bind it to an input, I'd expect the existing value of the input to initialize the selected single item in the tree drop down.


Do you have an example of this?


1 Reply

KR Keerthana Rajendran Syncfusion Team January 10, 2022 07:35 AM UTC

Hi Matt, 
 
Thanks for contacting Syncfusion support. 
 
You can get or set the value of EJ2 Dropdown Tree component using the value property. The change event will be triggered while changing the value in the Dropdown Tree. 
 
Refer to the following code. 
 
let treeObj: DropDownTree = new DropDownTree({ 
  fields: { 
    dataSource: (dataSource as any).defaultData, 
    value: 'id', 
    text: 'name', 
    child: 'subChild', 
    expanded: 'expanded', 
  }, 
  popupHeight: '200px', 
  placeholder: 'Select a folder or file', 
  changeOnBlur: false, 
  change: () => { 
    valueChange(); 
  }, 
}); 
treeObj.appendTo('#default'); 
function valueChange(): void { 
  (document.getElementById('value') as any).value = 
    treeObj.value && treeObj.value.length > 0 ? treeObj.value[0] : ''; // get value 
  (document.getElementById('text') as any).value = treeObj.text; 
} 
document.getElementById('value').onchange = function () { 
  treeObj.value = [this.value]; // set value; 
}; 
 
 
 
 
Please let us know if you need any further assistance. 
 
Regards, 
Keerthana R. 


Loader.
Up arrow icon