find row index on select event for rowHeaderContextMenu

3 posts, 0 answers
  1. Armando Canez
    Armando Canez avatar
    5 posts
    Member since:
    Aug 2009

    Posted 04 May 2018 Link to this post

    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. Armando Canez
    Armando Canez avatar
    5 posts
    Member since:
    Aug 2009

    Posted 07 May 2018 in reply to Armando Canez Link to this post

    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


  3. Veselin Tsvetanov
    Admin
    Veselin Tsvetanov avatar
    1201 posts

    Posted 08 May 2018 Link to this post

    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.
Back to Top