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
close icon

Need search option in tree view control

Hi, 
     I have been using tree view control with checkbox and i need an option to search node in tree view using a text box. Is it possible? kindly share a code or example.




Regards, 
Justin Ebenezer

6 Replies

CI Christopher Issac Sunder K Syncfusion Team April 1, 2019 10:25 AM UTC

Hi Justin Ebenezer, 

Greetings from Syncfusion!!! 

We have prepared a custom sample to filter Treeview nodes. Please check the below link 

In this sample, we have used a textbox for filtering Treeview items and in the change event of Textbox, we have filtered the items using Datamanager to update the Treeview datasource. 

Please check and get back to us if you have any further concerns. 

Thanks,
Christo 



EB Ebenezer April 2, 2019 11:59 AM UTC

Hi, 
     I just saw your example back then, having some issues while using that. 

1. If i check a node using search input option then corresponding node was still unchecked once i clear the input.
2. "let query = new Query().where(new Predicate.or(predicats));" compile error, that it should be void.
3. If i check some nodes without using search option and then if i try to search 'em it shows as unchecked.


Regards, 
Justin Ebenezer


CI Christopher Issac Sunder K Syncfusion Team April 3, 2019 12:55 PM UTC

Hi Justin Ebenezer, 

Thanks for the update. 

We have resolved the search and checking tree nodes while performing search operation related issues. In the provided sample, we have maintained the checked nodes in a private array and update it while changing the dataSource in the dataBound event. Also we disabled the autoCheck to achieve independent behavior of checked state.  


Please check the updated sample and let us know if you have any concerns. 

Thanks, 
Christo 



TC testuser cipl February 27, 2024 07:16 AM UTC

Screenshot_1.pngScreenshot_2.png

Hi team , search is working fine but am selected child node after clear the value entire parent all tree node selected how to resolve it . here am selected western America after I remove that search value then i see my tree its showing all selected in Australia. can you help on this issue

Here another one case is am searched parent node that time am selected parent value i need to push that all child node value in that array how we can achieve that

Regards,


Yuvi



TC test cipl February 27, 2024 03:36 PM UTC

Hi team , 



Am also getting same issue can you please help on this  but another place expecting once am searching parent node I need child node also its not came this is one of the scenario for me. Please help on this issue



JA Jafar Ali Shahulhameed Syncfusion Team March 2, 2024 06:16 PM UTC

Hi Test,


Based on the shared details we can understand that you are trying to utilize Syncfusion TreeView component and facing an issue while performing search operation. We have achieved your requirement by making the below changes,


[Query: All the nodes are getting selected]


We have resolved your query by using the Syncfusion TreeView component’s autoCheck property. We kindly suggest you to set false for the autoCheck property, so that node you check will be checked and other nodes are prevented from getting checked. Refer the code changes below,


[default.html]

 

<ejs-treeview #treeviewObj id="default" [showCheckBox]='true' [fields]='field' (dataBound)="dataBounded($event)" [autoCheck]='false' (nodeChecked)="nodeCheck($event)">

</ejs-treeview>


[Query: Getting the child nodes]


We can understand that you are trying to get the child nodes when their parent node is getting checked. We achieved it by using the TreeView component’s nodeChecked event, Kindly refer the code changes below,


[default.ts]

 

nodeCheck(args){

    ….

    let checkedNodeData = this.listTreeObj.getTreeData(args.data[0].id);

    if (checkedNodeData[0].hasChild) {

   // get child nodes array here

    let childNodes = this.getChildNodes(checkedNodeData[0].id);

    }

}

 

getChildNodes(parentId) {

  return this.localData.filter(node => (node as any).pid === parentId);

}


We have attached the sample for your reference,


Sample: https://stackblitz.com/edit/angular-tg9bew-rp3kwb?file=default.html,default.component.ts


Kindly check out the shared details and get back to us if you need further assistance.


Regards,

Jafar


Loader.
Live Chat Icon For mobile
Up arrow icon