How to detect new sheet insertion when it's done using the tab strip context me

Posted by: daniel on 15 May 2019, 6:00 am EST

  • Posted 15 May 2019, 6:00 am EST - Updated 3 October 2022, 1:51 am EST

    Hi,

    I’ve bound events that notify me when a new sheet is created when the “+” button is clicked on the tab strip. But sheets can also be inserted using the context menu of the tabs. If done in this second way I have so far not been able to a find documentation that tells me how to detect that a sheet was created. Is this possible?

  • Posted 15 May 2019, 7:11 pm EST

    Hi,

    This a known issue which is now fixed in the internal build. Fix will be included in the next stable build.

    Till then you may override the insertSheet command with a custom one to detect sheets insertion. Please refer to the following code snippet and the attached sample:

    function updateInsertSheetCommand(spread){
                var menuData = spread.contextMenu.menuData;
                for(var i = 0; i < menuData.length; i++){
                    if(menuData[i].command == "gc.spread.contextMenu.insertSheet"){
                        menuData[i].command = "insertSheet";
                        break;
                    }
                }
                var command = {
                    canUndo: false,
                    execute: function (wbContext, options, isUndo) {
                        var oldSheet = wbContext.getSheetFromName(options.sheetName);
                        var newSheet = new GC.Spread.Sheets.Worksheet();
                        wbContext.addSheet(wbContext.getSheetIndex(options.sheetName), newSheet);
                        setTimeout(function(){
                            onActiveSheetChanged(oldSheet, newSheet);
                        });
                        return true;
                    }
                };
                var commandManager = spread.commandManager();
                commandManager.register("insertSheet", command, null, false, false, false, false);
            }
    

    Regards

    updateContextMenuCommand.zip

  • Posted 16 May 2019, 2:04 am EST

    Thanks Sharad. Do you know when the next stable build will be out?

  • Posted 16 May 2019, 5:00 pm EST

    Hi Daniel,

    Spread v12.1.1(including the fix) was released just yesterday. You may download the latest build from the following link:

    http://cdn.grapecity.com/spreadjs/12.1.1/Files/SpreadJS.Release.12.1.1.zip

    Please upgrade to the latest version and let us know us if the issue still persists for you.

  • Posted 23 May 2019, 2:28 am EST

    Thanks Sharad - we’ll try it out

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels