How to Keep the Active Cell After Pressing Enter in SpreadJS?

Posted by: rhdmstj17 on 27 November 2024, 4:16 am EST

    • Post Options:
    • Link

    Posted 27 November 2024, 4:16 am EST

    I’m handling cell value changes in SpreadJS using the following code:

    // Handle value changes
    sheet.bind(GC.Spread.Sheets.Events.ValueChanged, function (e, info) {
        console.log('Value changed event triggered');
        handleChange(info, sheet);
    });

    Currently, when I press Enter after changing a cell’s value, the active cell **moves one row down **by default. However, I want the active cell to remain on the same cell where the value was entered.

    How can I achieve this behavior?

    Thank you in advance for your help!

  • Posted 27 November 2024, 5:59 am EST

    Hi,

    The current behaviour of the SpreadJS to move one row down is by design and aligns with the Microsoft Excel’s behaviour. For your use case, you could use the SpreadJS Events to achieve the same.

    Refer to the following code snippet:

    let cancelCellLeave = false;
    spread.bind(GC.Spread.Sheets.Events.LeaveCell, (sender, args) => {
        console.log("Leave Cell");
        console.log(args);
        if (cancelCellLeave) {
            cancelCellLeave = false;
            info.cancel = true;
        }
    })
    
    spread.bind(GC.Spread.Sheets.Events.EditEnded, (sender, args) => {
        console.log('Edit Ended');
        console.log(args);
        cancelCellLeave = true;
    });
    
    spread.bind(GC.Spread.Sheets.Events.ValueChanged, (sender, args) => {
        console.log('Value Changed');
        console.log(args);
    });

    Sample: https://jscodemine.mescius.io/share/QqLs0FkI60CQJh2A351naQ/?defaultOpen={"OpenedFileName"%3A["%2Fsrc%2Fapp.js"]%2C"ActiveFile"%3A"%2Fsrc%2Fapp.js"}

    References:

    EditEnded Event: https://developer.mescius.com/spreadjs/api/classes/GC.Spread.Sheets.Events#editended

    LeaveCell Event: https://developer.mescius.com/spreadjs/api/classes/GC.Spread.Sheets.Events#leavecell

    Regards,

    Ankit

Need extra support?

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

Learn More

Forum Channels