This is a migrated thread and some comments may be shown as answers.

find row index on select event for rowHeaderContextMenu

2 Answers 158 Views
Spreadsheet
This is a migrated thread and some comments may be shown as answers.
Armando Canez
Top achievements
Rank 1
Armando Canez asked on 04 May 2018, 11:00 PM

I need to perform a custom action on a row. For that I want to use the rowheader contextmenu.

How can I know wich row Index is the context menu being applied? the contextMenu e.target seems to be the whole spreadsheet.

I cannot find any clue in either contextmenu or spreadsheet  docs or forums.

var rowHeaderContextMenu = this.currentSpreadsheet.rowHeaderContextMenu();
rowHeaderContextMenu.remove("[data-action=delete-row]");
rowHeaderContextMenu.remove("[data-action=hide-row]");
rowHeaderContextMenu.append("<li id='myAction' data-action='row-customaction'>My custom action</li>");
 
rowHeaderContextMenu.bind('select', function(e){
    console.log('contextmenu row', e);

     var rowIndex = ?????????

     doMyCustomAction(rowIndex);

});

 

Extra points if the answer applies also for a cell / columnHeader.

Thanks in advance.

 

 

 

 

 

2 Answers, 1 is accepted

Sort by
0
Armando Canez
Top achievements
Rank 1
answered on 07 May 2018, 04:54 PM

The only way I could find how to do it is to assume when the contextMenu select event is called, the whole row is selected.
That allows me to do this:

 

var rowHeaderContextMenu = mySpreadsheet.rowHeaderContextMenu()
rowHeaderContextMenu.remove("[data-action=delete-row]");
rowHeaderContextMenu.append("<li id='myAction' data-action='row-customaction'>My custom action</li>");
 
rowHeaderContextMenu.bind('select', function(e){
    var rowIndexStart = mySpreadsheet.activeSheet().selection()._ref.topLeft.row;
    var rowIndexEnd =  mySpreadsheet.activeSheet().selection()._ref.bottomRight.row;
    var action = $(e.item).data('action');
 
    console.log('rowindex:', rowIndexStart + ' - ' + rowIndexEnd);
 
    for (var rowIndex = rowIndexStart;rowIndex <= rowIndexEnd; rowIndex++){
        switch(action){
            case 'row-custmaction':
                doMyCustomAction(rowIndex);
            break;
            default:
 
        }
    }
});

Added extra code to check form multiple row selection.
I hope this helps someone 

Armando


0
Veselin Tsvetanov
Telerik team
answered on 08 May 2018, 10:02 AM
Hello Armando,

Retrieving the selection from the Spreadsheet Sheet would be the appropriate approach in this scenario. When the rowHeaderContextMenu opens at least one row will always be selected on the currently active Sheet.

Regards,
Veselin Tsvetanov
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
Spreadsheet
Asked by
Armando Canez
Top achievements
Rank 1
Answers by
Armando Canez
Top achievements
Rank 1
Veselin Tsvetanov
Telerik team
Share this question
or