给你的文档里有自定义的办法,你根据实际需要实现几个接口就可以。
另外,有一个RadioCellType的例子,供你参考:
- var spreadNS = GcSpread.Sheets;
- $(document).ready(function ()
- {
- var spread = new GcSpread.Sheets.Spread(document.getElementById("ss"));
- initSpread(spread);
- });
- function RadioCellType()
- {
- }
- RadioCellType.prototype = new spreadNS.CustomCellType();
- RadioCellType.prototype.paint = function (ctx, value, x, y, w, h, style, options)
- {
- spreadNS.CustomCellType.prototype.paint.apply(this, [ctx, value, x, y, w, h, style, options]);
- };
- RadioCellType.prototype.createEditorElement = function ()
- {
- var div = document.createElement("div");
- var $div = $(div);
- $div.attr("gcUIElement", "gcEditingInput");
- $div.css("background-color", "white");
- $div.css("position", "absolute");
- $div.css("overflow", "hidden");
- $div.css("border", "2px #5292f7 solid");
- var $input1 = $("<input type='radio' name='gender' value='male'/>Male<br>");
- var $input2 = $("<input type='radio' name='gender' value='female'/>Female<br>");
- $div.append($input1);
- $div.append($input2);
- return div;
- };
- RadioCellType.prototype.getEditorValue = function (editorContext)
- {
- if (editorContext && editorContext.children.length === 4)
- {
- var input1 = editorContext.children[0];
- var input2 = editorContext.children[2];
- if (input1.checked == true)
- return "male"
- if (input2.checked == true)
- return "female"
- }
- };
- RadioCellType.prototype.setEditorValue = function (editorContext, value)
- {
- if (editorContext && editorContext.children.length === 4)
- {
- var input1 = editorContext.children[0];
- var input2 = editorContext.children[2];
- if (value == "male")
- {
- input1.setAttribute("checked", true)
- } else
- {
- input2.setAttribute("checked", true)
- }
- }
- };
- RadioCellType.prototype.isEditingValueChanged = function (oldValue, newValue)
- {
- if (newValue != oldValue)
- {
- return true;
- }
- return false;
- };
- RadioCellType.prototype.updateEditor = function (editorContext, cellStyle, cellRect)
- {
- if (editorContext)
- {
- $(editorContext).width(cellRect.width);
- $(editorContext).height(100);
- }
- };
复制代码 |