x-spreadsheet icon indicating copy to clipboard operation
x-spreadsheet copied to clipboard

Event when the user changes sheets

Open oh-wo opened this issue 3 years ago • 3 comments

Hi there,

Thanks very much for this excellent project.

Currently when the user changes sheets I don't think there is any way to be notified of this programmatically. Would you be interested in supporting that kind of functionality?

We need to know when the user has changed sheets because we monitor what the user has selected and transform this and use the output in our application.

Some options:

  1. Fire CELL_SELECTED / CELL_SELECTED events because the selected data has changed.
  2. Fire a new SHEET_CHANGED event

oh-wo avatar May 11 '21 10:05 oh-wo

I doubt this would be implemented because events are missing for lots of stuff, not just this.

You should just fork this and fire a custom event yourself using an evemtEmitter

I'm currently re-writing the entire app to have custom events for everything on my own fork and to use composition over inheritance hell.

MartinDawson avatar May 17 '21 08:05 MartinDawson

You can fire custom events in the correct life cycle, see sheet.js trigger with on.

HondryTravis avatar May 20 '21 01:05 HondryTravis

If there was an easier way, I missed it :-) This is how I have solved getting the sheet index. Not very elegant, but I added an onclick event on the div and then, via the className, get the text/index

<div onClick={handleOnClick} id={this.spreadsheetId} />
const handleOnClick = (e) => {
  const xSpreadSheet = this.xSpreadSheet.getData();
  if (e.target.parentNode.className === 'x-spreadsheet-menu') {
    const newSheetIndex = xSpreadSheet.findIndex(
      (item) => item.name === e.target.innerText
    );
    return newSheetIndex
  }
};

fakob avatar Mar 27 '22 20:03 fakob