Posted 23 March 2018, 9:39 pm EST
That example is definitely getting on the right track. Let me see if I can come up with something a bit closer to what I want, and then you can suggest the better way to do it using Flexsheet.
class CustomCell {
constructor(public Sheet: number, public Row: number, public Col: number) { }
}
. . .
flexSheetInit(flexSheet: wjcGridSheet.FlexSheet) {
//stuff
for (let i = 0; i < Object.keys(dataFromServer).length; i++) {
// dynamically creating bound sheets for the flexsheet control (using JSON)
this.ServerWorkbook.addBoundSheet(dataFromServer[i].SheetName, dataFromServer[i].IndividualTabdata);
}
// object for storing all out desired Cells to Mirror (Is there a better way to reference Cells that I could pull from my dataFromServer?)
const CellsToMirror = [];
CellsToMirror.push(new CustomCell(1,1,1));
CellsToMirror.push(new CustomCell(2,2,2));
CellsToMirror.push(new CustomCell(2,2,3));
// pass our array of 3 cells we want to mirror each other
this.addMirroredCells(CellsToMirror);
. . .
addMirroredCells(customCellArray : CustomCell []) {
// we itterate over all the cells we want to mirror data to
for (let i = 0; i < customCellArray.length; i++) {
// add an event handler for each cell
this.ServerWorkbook.cellEditEnded.addHandler((refFlexGrid, e) => {
// grab the value of this edited cell
const data = refFlexGrid.sheets[customCellArray[i].Sheet].grid.getCellData(customCellArray[i].Row,customCellArray[i].Col);
// This itterates over the whole list of cells, and as long as it isn't the current cell, it copies its value to the cell.
for (let j = 0; j < customCellArray.length; j++)
if (i !== j) {
refFlexGrid.sheets[customCellArray[j].Sheet].grid.setCellData(customCellArray[j].Row, customCellArray[j].Col, data, false, false);
}
});
}
}
Ok so that doesn’t quite work, but should show you my thinking. The addHandler I don’t fully understand, as it looks like the event is tied to the workbook/flexsheet and not to individual cells.
I might want to add 100s of different groups of mirrored cells among dozens of different pages, and I need to somehow group them all using data from my json object from the server. A flexsheet binds to simple string data using addBoundSheet(), so I’d like to pull data from there to somehow get them all mirrored, on a worksheet that could add and remove rows potentially on the client before saving back. Another option is adding another object to my server data that has a list of all the cells that need to merge to each other, but getting to a solution is hard without understanding deeply how the cellEditEnded.addHandler works.
The way I have it now doesn’t really bind on the event (e) since I don’t want every cell mirroring each other, just the ones I define.
With this extra info, is my question more clear?