x-spreadsheet
x-spreadsheet copied to clipboard
Event when the user changes sheets
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:
- Fire
CELL_SELECTED
/CELL_SELECTED
events because the selected data has changed. - Fire a new
SHEET_CHANGED
event
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.
You can fire custom events in the correct life cycle, see sheet.js
trigger
with on
.
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
}
};