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

The 'collectionChange' event is not triggered when nodes are ungrouped.

Hello Syncfusion Team,

Our app uses Syncfusion's DiagramComponent ("@syncfusion/ej2-angular-diagrams": "^17.3.26").

In our app, we'd like to save the user's diagram whenever the user groups or ungroups nodes.

We received the collectionChange event when nodes are grouped together.

However no events are seemingly triggered when the grouped nodes are ungrouped. 

I have a stackblitz demo here (please see the console log there): https://stackblitz.com/edit/diagram-ungroup-no-event

Is this a bug or am I doing something wrong?

Thanks,
Mithun

3 Replies

SG Shyam G Syncfusion Team December 6, 2019 06:09 AM UTC

Hi Mithun, 

Please use historyChange event to track the group/ungroup action. Please refer to a code example and modified sample below. 

Code example: 
//inject undo redo module  
Diagram.Inject(UndoRedo) 

<ejs-diagram #diagramControl id="diagram-control" 
      width="100%" height="500px" 
      [contextMenuSettings]="this.contextMenuSettings" 
      (collectionChange)="onCollectionChange($event)" 
      (historyChange)="onHistoryChange($event)"  
      (created)="onCreated()"> 
    </ejs-diagram> 

onHistoryChange(args: IHistoryChangeArgs) {  
    if((args.change as any).type === 'Group' || (args.change as any).type === 'UnGroup') { 
        console.log(`historychange`); 
   
 





Regards, 
Shyam G 



MI Mithun December 6, 2019 08:50 AM UTC

Thanks Shyam. That worked! 

A small concern though... 

(args.change as any).type === 'Group'

The '.type' property does not seem to be a publicly documented property of  'SelectorModel' (which is the type of args.change).

Just want to future-proof my solution so there are no inadvertent breaking changes in future. 

Thanks,
-Mithun





SG Shyam G Syncfusion Team December 9, 2019 04:21 AM UTC

Hi Mithun, 

Sorry for the inconvenience. 

To achieve your requirement, we use interface to implement the type. Please refer to a code example and sample below. 

Code example: 
interface IHistory { 
  type: string 

onHistoryChange(args: IHistoryChangeArgs) {   
    if((args.change as IHistory).type === 'Group' || (args.change as IHistory).type === 'UnGroup') { 
        console.log(`historychange`); 
   
  }  



Regards, 
Shyam G 


Loader.
Live Chat Icon For mobile
Up arrow icon