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

Select Fired After BeforeOpen ContextMenu

I used the how-to for a context menu in a tree view:

The problem I am facing is that the select event is fired after the context menu beforeopen one, so that I get null on the first call, and the previously selected node on subsequent right-clicks.

Am I missing something obvious?

Many thanks

My code 

<ejs-treeview #filesTree id='filesTree' [fields]='field' (nodeDragStop)="onDragStopped($event)" (nodeDragging)="onDragging($event)" (nodeSelected)='nodeSelected($event)'
[allowEditing]='canChange' (nodeEdited)='onNodeEdited($event)'
(nodeDropped)="onNodeDropped($event)" allowMultiSelection=false allowDragAndDrop=true></ejs-treeview>
<!-- -->
</div>
<ejs-contextmenu #fileContextMenu id='fileContextMenu' target='#filesTree' [items]='menuItems' (select)='menuclick($event)' (beforeOpen)='beforeopen($event)' ></ejs-contextmenu>

5 Replies

NP Narayanasamy Panneer Selvam Syncfusion Team August 25, 2019 03:07 AM UTC

Hi Frederik, 
 
Greetings from Syncfusion support. 
 
We have validated your query and have prepared a sample based on the reported scenario. But we could not able to reproduce your issue at our end.  
Video reference: Output 
If the sample takes more time to load, then please run it in an incognito window. 
If still the reported issue is persisting at your end, Kindly modify the shared sample to reproduce the reported issue. It will be more helpful to assist you better. 
 
Regards, 
Narayanasamy P. 



FR frederik August 26, 2019 07:13 AM UTC

The issue might be with self-referential data. I've edited the sample to reproduce the error.


The first right-click will show 'undefined' selected item. Clicking outside of the tree and then right-click again will keep on showing undefined. Selecting one, and then and then right-clicking another will show the id of the previously selected one.


Many thanks


AB Ashokkumar Balasubramanian Syncfusion Team August 26, 2019 11:25 AM UTC

Hi Frederik, 
 
We have checked the reported issue and it was due to in some cases the beforeOpen event gets triggered even before the SelectedNode value gets initialized. So, you can use the following code snippet to get the target tree node in the beforeOpen event of the context menu
 
if ((args.event.target as any).closest('li')) { 
        this.targetNodeId = (args.event.target as any).closest('li').getAttribute("data-uid"); 
    } 
 
 
Please check the above sample and get back to us if you need any further assistance. 
 
Regards, 
Ashokkumar B. 



FR frederik August 27, 2019 06:03 AM UTC

Thank you - this should do the trick


AB Ashokkumar Balasubramanian Syncfusion Team August 27, 2019 09:39 AM UTC

Hi Frederik, 
 
Most Welcome. 
 
Please let us know, if you need any further assistance. 
 
Regards, 
Ashokkumar B. 


Loader.
Live Chat Icon For mobile
Up arrow icon