Posted 29 July 2021, 3:11 am EST
Hi,
For this, you need to follow two first is define typeName property on custom function class and then expose the custom function class to the window object. Please refer to the following code snippet and attached updated sample that demonstrates the same.
export class FullNameCellType extends GC.Spread.Sheets.CellTypes.Base {
constructor(eventId) {
super();
this.typeName = "FullNameCellType";
this.eventId = eventId;
}
paint(ctx, value, x, y, w, h, style, options) {
if (value) {
spreadNS.CellTypes.Base.prototype.paint.apply(this, [
ctx,
value.firstName + "." + value.lastName,
x,
y,
w,
h,
style,
options
]);
}
}
updateEditor(editorContext, cellStyle, cellRect) {
if (editorContext) {
editorContext.style.width = cellRect.width;
editorContext.style.height = 100;
return { height: 100 };
}
}
createEditorElement() {
var div = document.createElement("div");
div.setAttribute("gcUIElement", "gcEditingInput");
div.style.backgroundColor = "white";
div.style.overflow = "hidden";
var span1 = document.createElement("span");
span1.style.display = "block";
var span2 = document.createElement("span");
span2.style.display = "block";
var input1 = document.createElement("input");
var input2 = document.createElement("input");
var type = document.createAttribute("type");
type.nodeValue = "text";
var clonedType = type.cloneNode(true);
input1.setAttributeNode(type);
input2.setAttributeNode(clonedType);
div.appendChild(span1);
div.appendChild(input1);
div.appendChild(span2);
div.appendChild(input2);
return div;
}
getEditorValue(editorContext) {
if (editorContext && editorContext.children.length === 4) {
var input1 = editorContext.children[1];
var firstName = input1.value;
var input2 = editorContext.children[3];
var lastName = input2.value;
return { firstName: firstName, lastName: lastName };
}
}
setEditorValue(editorContext, value) {
if (editorContext && editorContext.children.length === 4) {
var span1 = editorContext.children[0];
span1.innerHTML = "First Name:";
var span2 = editorContext.children[2];
span2.innerHTML = "Last Name:";
if (value) {
var input1 = editorContext.children[1];
input1.value = value.firstName;
var input2 = editorContext.children[3];
input2.value = value.lastName;
}
}
}
}
window["FullNameCellType"] = FullNameCellType;
sample: https://codesandbox.io/s/spreadjs-custom-cell-save-json-forked-0nuz3
Also please refer to the following demo which demonstrates how you could serialize the custom Item in SpreadJS.
custom Item serialize Demo:https://www.grapecity.com/spreadjs/demos/features/workbook/custom-item-serialization#demo_source_name
Regards
Avinash