Implementation of insertCopiedCells/insertCutCells present in context menu

Posted by: dpandey on 26 August 2026, 5:59 pm EST

  • Posted 26 August 2026, 5:59 pm EST

    Hi there ,

    I am trying to implement Implementation of insertCopiedCells/insertCutCells option present in context menu (in viewport contextMenu , row header context menu ,column header context menu)

    {THis option appears in context menu once you copy anything}

    So one approach is to use the native spread functionality , if I use that then how to handle the collaborative operations for that …

    And suppose if I want to do the custom implementation of this , how to replicate that …Can you provide the function…

  • Posted 27 August 2026, 9:23 am EST

    Hi,

    We are not completely clear on the exact requirement and the expected behavior you are trying to achieve. Could you please elaborate further with a specific example or use case?

    Also, could you please clarify the following points:

    You mentioned using the native SpreadJS functionality and asked how to handle collaborative operations with it. Could you explain what you mean by “if I use the native spread functionality, then how to handle the collaborative operations for that”? For example, are you using a specific collaboration/real-time synchronization mechanism, and do you expect the insertCopiedCells/insertCutCells operation to be synchronized with other users?

    You also mentioned a custom implementation and asked how to replicate the functionality. Could you clarify what you mean by “custom implementation of this”? Are you looking for an API/function that performs the same operation as the built-in Insert Copied Cells / Insert Cut Cells context-menu commands, or are you looking to implement the complete behavior independently?

    If possible, please provide a small example describing:

    The initial cell/range configuration.

    What is copied or cut.

    Where the user invokes Insert Copied Cells / Insert Cut Cells.

    The expected result.

    How the operation should behave in your collaborative scenario.

    For example, if you could provide something like:

    Cells A1:C3 are copied, the user right-clicks on E1 and selects “Insert Copied Cells”, and we expect the copied cells to be inserted at E1 while shifting the existing cells to the right. This operation should also be propagated to other connected users.

    This would help us better understand the requirement and determine whether the native SpreadJS functionality can be used directly or whether a custom implementation/API would be required.

    Regards,

    Priyam

  • Posted 27 August 2026, 9:59 am EST - Updated 27 August 2026, 10:22 am EST

    Hi Priyam ,

    I am trying to implement the insert Copied cells /insert Cut cells functionality (have attached the gif of that)…

    So , here are two options either to use the built in functionality Insert Copied Cells / Insert Cut Cells context-menu commands…in this option the context menu commands will handle the operation , I need to take care of the real time collaboration of that …but in doing that I am not aware of how to handle the shifting of cells right/down( is there any event trigger available on spread for that)…

    And then the second option is to do the custom implementation …and yes by custom implementation i mean API/function that performs the same operation as the built-in Insert Copied Cells / Insert Cut Cells context-menu commands…

    Here is the gif:

    yes , The exact operations should also be propagated to the to other connected users.

    Regards

    Deepak

  • Posted 28 August 2026, 5:07 am EST - Updated 28 August 2026, 5:15 am EST

    Hi,

    Thank you for the clarification and for providing the additional details.

    Based on your requirement, we recommend using the built-in Insert Copied Cells / Insert Cut Cells context-menu functionality rather than implementing the operation manually.

    The following built-in commands are available for these operations:

    InsertCopiedCellsShiftCellsRight

    InsertCopiedCellsShiftCellsDown

    InsertCutCellsShiftCellsRight

    InsertCutCellsShiftCellsDown

    When these commands are triggered through the built-in context menu, SpreadJS handles the cell-shifting operation internally.

    For your collaboration scenario, using the native functionality is also recommended because the built-in operation is integrated with the collaboration mechanism. This allows the insert/shift operation to be synchronized with other connected users without having to manually calculate the affected ranges or recreate the operation for collaboration. Refer to the attached gif and demo: https://developer.mescius.com/spreadjs/demos/collaboration/login

    If you need to monitor when the operation occurs for logging or other application-specific processing, you can check the clipboard events. For example:

    // Fires BEFORE insert (can cancel)
    spread.bind(GC.Spread.Sheets.Events.ClipboardPasting, (sender, args) => {
      if (args.shiftCells !== undefined) {
        // args.shiftCells: 0 = right, 1 = down
        // args.isCutting: true for cut, false for copy
        console.log("Insert copied/cut cells triggered", args);
      }
    });
    
    // Fires AFTER insert (for post-sync logic)
    spread.bind(GC.Spread.Sheets.Events.ClipboardPasted, (sender, args) => {
      if (args.shiftCells !== undefined) {
        // Operation already synced to other users via collaboration
        console.log("Insert completed and synced", args);
      }
    });

    Here, args.shiftCells can be used to determine the shift direction:

    0 — Shift Cells Right

    1 — Shift Cells Down

    Regarding a custom implementation

    Although it is possible to implement the behavior manually, we do not recommend doing so for a collaborative scenario. A custom implementation would require you to handle the cell shifting, affected ranges, clipboard state, and synchronization of the operation with other users. It could also require additional handling for scenarios involving merged cells, tables, spans, formulas, and other worksheet features.

    Therefore, for your requirement, we recommend using the built-in Insert Copied Cells / Insert Cut Cells commands and relying on the collaboration mechanism to propagate the operation to the other connected users.

    If there is a specific limitation with the built-in commands that prevents you from using them in your collaboration implementation, please let us know the exact scenario, and we can investigate it further.

    Regards,

    Priyam

Need extra support?

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

Learn More

Forum Channels