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

Context Menu for several selected records

Hi,

I understand the context menu is by default operating on the selectedRecord.

When I right click on a row, even if before I had selected several of them, only that records gets selected and the context menu appears.

Is there a way so that when I right click to open the context menu, my selection does not change to that single row and it keeps all previous rows selected? This way I would be able to apply context menu "actions" to several rows at a time.

Thank you in advance for your help.

Kind regards,
Carlos

3 Replies

MS Madhu Sudhanan P Syncfusion Team October 24, 2016 01:48 PM UTC

Hi Carlos, 

Currently the Grid will clear the selection when context menu is opened.  But we can achieve your requirement with the below code example. 


       var cached; //Local variable to store selected indexes 
        
       $("#Grid").ejGrid({ 
 
            dataSource: window.gridData, 
            selectionType: 'multiple', 
            contextMenuSettings: { enableContextMenu: true }, 
            . . .  . .  
            contextOpen: function () { 
                if (cache) 
                    this.selectRows(cache); //Select after context menu open 
            }, 
            rowSelecting: function (args) { 
 
                //Store the selected indexes which can be selected after context opened. 
 
                if (this.selectedRowsIndexes.length > 1) { 
                    cache = this.selectedRowsIndexes.slice(0); 
                    cache.push(args.rowIndex); 
                } 
                else { 
                    cache = null; 
                } 
            } 
        }); 


In the above code example we have stored the selected indexes in the rowSelecting event and re-selected them after context menu opened in the contextOpen event. 




Regards, 
Madhu Sudhanan P 



CR Carlos Rodríguez García October 25, 2016 01:05 PM UTC

Thank you very much, this worked perfect.


MS Madhu Sudhanan P Syncfusion Team October 26, 2016 05:27 AM UTC

 
We are happy that your requirement is achieved. 
 
Please get back to us if you require further assistance. 
 
Thanks & regards, 
Madhu Sudhanan P 


Loader.
Up arrow icon