Event tracking setFormatter

Posted by: davide.vago on 8 January 2020, 11:52 am EST

    • Post Options:
    • Link

    Posted 8 January 2020, 11:52 am EST

    Good morning/afternoon.

    Given a spreadsheet (workbook) instance, I’ve started implementing a small custom toolbar to permit the user to format cells (e.g. percentage, increase/decrease decimals) but I’m struggling to trigger actions on change of the format within a selection.

    I’ve got a custom stats bar (like the one from MS Excel) that tells me information related to max/min of the selection and I would like to update the values accordingly with the format set by the user via the toolbar, however I can’t find a way to listen for this formatter change.

    (ref. https://www.grapecity.com/spreadjs/docs/v13/online/SpreadJS~GC.Spread.Sheets.Events.html)

    Do you have any recommendation or best practice to achieve the above?

    Thanks in advance for your support.

  • Posted 9 January 2020, 12:17 am EST

    Hi Davide,

    SpreadJS provides events only for the actions which are performed by the user on SpreadJS such as changing selection, editing cells etc. Events are provided for the actions which are performed using the API and it makes sense because we are already aware of those actions.

    In this case, the toolbar is not part of the SJS and when a button on the toolbar is clicked some action is performed on SJS workbook using the API which is why events are not fired. So I would recommend you to create a custom event bus, which would notify you whenever any action is executed successfully. General idea should be like this:

    // toolbar button is clicked, perform some action like change formatting
    fomatterButtonClickhandler(){
    	// make changes to SJS workbook using the API
    	sheet.setFormatter(rowIndex, colIndex, "format_string");
    	// format changed successfully, now dispatch over custom event
    	customEventBus.dispatch({
    		type: CustomEventTypes.FormatChanged
    		args: "any aditional arguments, like sheetName, spread instance, selection info etc"
    	});
    }
    

    ~sharad

  • Posted 27 March 2023, 5:18 am EST - Updated 28 March 2023, 2:26 am EST

    One possible solution to achieve the above is to use the SpreadJS event handler to listen for changes in the format of the selected cells. You can add an event listener to the SpreadJS instance and have it listen for changes in the format of the selected cells and then trigger an action upon detecting a change in the format. For example, you can use the‘Click’event handler to listen for a change in the format and then update the stats bar accordingly. This will ensure that the stats bar will always reflect the latest changes in the format of the selected cells.

  • Posted 28 March 2023, 5:10 am EST

    Hello,

    It is important to note that SpreadJS provides events when there is some action performed by the user. These actions include changing cell value, changing selection, clicking cell etc. But when changes are done with the help of APIs provided by SpreadJS, the events do not get triggered.

    If you want to trigger the events corresponding to changes, you need to execute their respective commands to perform actions using command manager of spread. These commands are the same which are executed when user performs some action on spread. For instance, you can execute “editCell” command with commandManager.execute() API method, this will also trigger the ‘CellChanged’ event.

    Further, if you want to get notified after performing some actions on spread, you can encapsulate those actions by creating custom commands and use a custom event bus. So, when a custom command is executed, it will trigger the respective event in the custom event bus.

    Regards,

    Avinash

Need extra support?

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

Learn More

Forum Channels