Posted 5 November 2024, 6:04 am EST - Updated 5 November 2024, 6:07 am EST
Hello,
I wanted to create a custom combo box cell type based on the default ComboBox cell type class. However, using my codes below, an exception occured in calling “createEditorElement” method of the base class every time when I clicked the arrow in Cell A1. Do you see any issues in my implementaion codes?
import * as GC from '@mescius/spread-sheets';
import '@mescius/spread-sheets/styles/gc.spread.sheets.excel2016black.css';
import * as React from 'react';
import './App.css';
import Sheets = GC.Spread.Sheets;
class MyComboBoxCellType extends Sheets.CellTypes.ComboBox {
constructor() {
super();
const items = ["Item1", "Item2", "Item3"];
this.items(items);
}
public override createEditorElement(
context?: { sheet: Sheets.Worksheet, row: number, col: number, sheetArea: Sheets.SheetArea }
) {
const editor = super.createEditorElement(context); // <-- An exception was thrown inside here!!
return editor;
}
}
export default function App() {
const host = React.useRef<HTMLDivElement | null>(null);
React.useEffect(
() => {
const workbook = new Sheets.Workbook(host.current!, { sheetCount: 1 });
const sheet = workbook.getSheet(0);
sheet.getCell(0, 0).cellType(new MyComboBoxCellType());
return () => workbook.destroy();
},
[]
);
return (
<div ref={host} style={{ height: "90vh", width: "100%" }} />
);
}
Here is the link to your API document I referenced:
https://developer.mescius.com/spreadjs/api/classes/GC.Spread.Sheets.CellTypes.CheckBox#createeditorelement