undoTransaction doesn't trigger any event

Posted by: davide.vago on 5 May 2021, 3:38 am EST

  • Posted 5 May 2021, 3:38 am EST

    Hi there,

    I'm reaching you out as I was trying to implement some extra logic attached to the Undo event from a dragFill event.

    I've been using this approach to permit the user to fill cells via keyboard shortcuts: https://codesandbox.io/s/lucid-raman-1ydsm?file=/src/index.js:1488-1610 (this sandbox was provided as example of drag fill shortcut from your support a while ago).

    It appears that after the ctrl+Z/cmd+Z keystrokes, the command executes correctly, however there is no way to capture the undo event in any of the SJS Events (GC.Spread.Sheets.Events), e.g. RangeChanged, CellChanged, ClipboardPasted, DragFillBlockCompleted.

    I would expect the RangeChanged should trigger as per the undo event of a paste operation/manual drag fill.

    Looking forward to hearing from you

  • Replied 5 May 2021, 11:28 pm EST

    Hi Davide,

    We are able to replicate the issue at our end hence we have escalated this issue to the concerned team for further investigation. We will update you regarding this as soon as we get any information. The internal ID for this issue will be SJS-8654.

  • Replied 19 May 2021, 11:35 pm EST

    Hi Davide,

    The Devs informed us that. this is by design. The event will not be fired by a custom command, because we don't know what's the custom command do.

  • Replied 23 May 2021, 7:56 pm EST

    Hi Avinash,

    As far as I understand the RangeChanged should be triggered every time something changes in a given cellRange, meaning: If the undoTransaction of the custom command modifies the given cellRange I would expect the event RangeChanged to trigger.

    Given your devs say it's by design, what would it be a solution to achieve the Undo tracking? Please provide a clean solution.

    Looking forward to hearing from you
  • Marked as Answer

    Replied 25 May 2021, 10:26 pm EST

    Hi Davide,

    Since it is by design. What we could do is create a custom event bus and before executing the undo transaction just publish the custom event. Please refer to the following code snippet and attached sample that demonstrates the same.

    subscribe("rangeChangedOnUndo", (args) => {
    console.log("range changed", args);
    var command = {
    canUndo: true,
    execute: function (spread, options, isUndo) {
    var Commands = GC.Spread.Sheets.Commands;
    if (isUndo) {
    publish("rangeChangedOnUndo", {
    name: options.cmd,
    sheet: spread.getActiveSheet(),
    options: options,
    changedRange: options.drange
    Commands.undoTransaction(spread, options);
    return true;
    } else {
    Commands.startTransaction(spread, options);
    let selections = spread.getActiveSheet().getSelections();
    options.cmd = "ctrlFill";
    selections.forEach((sel) => {
    let srange = (options.srange = new GC.Spread.Sheets.Range(
    let drange = (options.drange = new GC.Spread.Sheets.Range(
    sel.row + 1,
    sel.rowCount - 1,

    cmd: "fill",
    sheetName: spread.getActiveSheet().name(),
    startRange: srange,
    fillRange: drange,
    autoFillType: GC.Spread.Sheets.Fill.AutoFillType.fillSeries,
    fillDirection: GC.Spread.Sheets.Fill.FillDirection.down
    Commands.endTransaction(spread, options);
    return true;

    Sample: https://codesandbox.io/s/sharp-kepler-n1624?file=/src/index.js:239-1794

Need extra support?

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

Learn More

Forum Channels