We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Not able to set the value of selected item in edit screen.

I am creating my dropdown tree list and have records in my data which is mapped to datasource

       dropDownTreeObject = new ej.dropdowns.DropDownTree({                             

                                fields: { dataSource: data, value: 'Id', text: 'Name', child: 'ChildItems' },

                            });                           

        dropDownTreeObject .appendTo('#ddtreeelement');                           

        dropDownTreeObject .value = 1;

But when i am trying to set value 

  dropDownTreeObject.value = 1;

ddtree is not setting the value for 1 and my data list has a record with Id 1.

Do I need to map value in any other way for setting in dropdown tree list?


2 Replies

IL Indhumathy Loganathan Syncfusion Team February 9, 2023 02:20 PM UTC

Hi Remya,


From the shared details, we understand that you want to bind value property for the Dropdown Tree component. You can follow the below way to achieve this requirement.


// Initialize  the Dropdown Tree control

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,

  value: ['01'],

});

treeObj.appendTo('#default');


Sample: https://stackblitz.com/edit/pdqzsg?file=index.html,index.ts


You can even bind multiple values just by specifying their corresponding values after enabling multi-selection in Dropdown Tree.


https://ej2.syncfusion.com/demos/#/bootstrap5/drop-down-tree/multiple-selection.html


Regards,

Indhumathy L



RP Remya Pillai February 10, 2023 01:12 PM UTC

Thanks. It Worked....


Loader.
Up arrow icon