Detecting value change in a cell

Posted by: jb9244 on 8 September 2017, 10:09 am EST

    • Post Options:
    • Link

    Posted 8 September 2017, 10:09 am EST

    What event(s) do I need to bind on a sheet to be notified when a cell’s value changes for any reason, for example:

    • User manually changes cell value
    • Cell’s formula results in a new value, for example, firing an event for B1 when B1 has “=A1” as a formula, and A1’s value changes
    • Pasting of data into cell
    • “Fill down” of a cell
    • Undo/redo

      … etc

    Documentation for CellChanged suggests anything that would cause the cell to be repainted would fire the event, however it only triggers in the first scenario above, but not in any of the other scenarios. ValueChanged is the same.

    Thanks.

  • Posted 8 September 2017, 10:09 am EST

    Hello,

    We have a list of all events documented online here:

    http://sphelp.grapecity.com/webhelp/SpreadSheets10/webframe.html#JavascriptLibrary~GC.Spread.Sheets.Events.html

    You can check in CellChanged event for what caused the event to fire using the code as follows:



    sheet.bind(GC.Spread.Sheets.Events.CellChanged, function (e, info) {

    if (info.propertyName === “value”) {

    alert(“cellChanged”);

    }

    });

    Above code will work for all scenarios which will cause the change in cell value like undo/redo, formula, code, etc.

    Please refer to the attached HTML page to know about all other events.

    Regards,

    Deepak Sharma

    2017/06/CellChangedSpreadJS.html

  • Posted 8 September 2017, 10:09 am EST

    Using your attached CellChangedSpreadJS.html:

    • If you type something into A1 and hit enter, the “cellChanged” alert will appear

    • If you now hit the delete key on A1 to clear the cell, you will not get the “cellChanged” alert, which is unexpected

    • If you enter “=A1” into B1, you will not get the “cellChanged” alert, which is unexpected, as B1 now has a value of 0 instead of null:

    >sheet.getValue(0,1)

    null

    … and after “=A1” entered…

    >sheet.getValue(0,1)

    0

    • If you then enter “a” into A1, you’ll get the “cellChanged” alert for A1, but no alert for B1’s value change (which occurred due to the formula).

    Any advice? Thanks.

  • Posted 8 September 2017, 10:09 am EST

    Hi Jason,

    RangeChanged event fires for Formula Update or Delete since these actions may involve multiple cells and hence can cause performance issue with CellChanged event.

    Please use the code below:

    [js]

    var spread,sheet;

    window.onload = function () {

    spread = new GC.Spread.Sheets.Workbook(document.getElementById(“spreadSheet”), { sheetCount: 3 });

    sheet = spread.getActiveSheet();

    spread.options.allowUserEditFormula = true;

    //this event will fire for formula and value changed

    sheet.bind(GC.Spread.Sheets.Events.CellChanged, function (e, info) {

    if (info.propertyName === “value”) {

    alert(“cellChanged”);

    }

    });

    sheet.bind(GC.Spread.Sheets.Events.DragFillBlock, function (e, info) {

    alert(“Direction (” + info.fillDirection + “)”);

    });

    sheet.bind(GC.Spread.Sheets.Events.ClipboardPasting, function (sender, args) {

    alert(“ClipboardPasting”);

    });

    sheet.bind(GC.Spread.Sheets.Events.UserFormulaEntered, function (e, info) {

    alert(“Formula (” + info.formula + “)”);

    });

            sheet.bind(GC.Spread.Sheets.Events.RangeChanged, function (sender, args) {
                console.log(args.sheetName, args.action);
            });
        }
    

    [/js]

    I hope it helps you.

    Regards,

    Deepak Sharma

  • Posted 29 August 2018, 6:24 pm EST

    I have this same issue, but in Angular. Using CellChanged only detects changes made if I click into a cell and manually change it. Clipboard pastes do not get registered:

    html:

     <gc-spread-sheets  (rowChanged)="rowChanged($event)" (cellChanged)="cellChanged($event)" [backColor]="spreadBackColor" [hostStyle]="hostStyle" (workbookInitialized)="workbookInit($event)">
    </gc-spread-sheets> 
    

    my.component.ts:

        cellChanged(args) {
            if (args.propertyName === "value") {
                console.log("Cell changed!");
            }
        }
    

    Any ideas?

  • Posted 6 May 2020, 12:33 pm EST

    RangeChanged seems to work for DeleteKey…

    However the event fires twice because for 2 different actions

    Where can I find documentation on what these actions represent?:

    args:
    	action: 6
    	changedCells: (3) [{…}, {…}, {…}]
    	col: 0
    	colCount: 36
    	row: 0
    	rowCount: 4
    	sheet: a {yn: 5, options: {…}, Zs: a, Jl: 2, Kl: 17, …}
    	sheetName: "Sheet1"
    	__proto__: Object
    
    action: 2
    changedCells: [{…}]
    col: 17
    colCount: 1
    row: 2
    rowCount: 1
    sheet: a {yn: 5, options: {…}, Zs: a, Jl: 2, Kl: 17, …}
    sheetName: "Sheet1"
    
  • Posted 7 May 2020, 2:59 am EST

    Hi,

    You may refer to the following doc for a reference of different range changed actions:

    https://www.grapecity.com/spreadjs/docs/v13/online/SpreadJS~GC.Spread.Sheets.RangeChangedAction.html

    Regards

Need extra support?

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

Learn More

Forum Channels