function NumberCellType(numType, spread) {
debugger;
this.spread = spread;
var self = this;
this.numType = SetNumType(numType);
function SetNumType(numType) {
debugger;
if (numType.FormatText) {
var num = numType.FormatText;
var x = String(num).indexOf(".") + 1;//得到小数点的位置
var y = String(num).length - x;//小数点的位数
numType.DecimalPlaces = y;
}
return numType
}
}
NumberCellType.prototype = new GC.Spread.Sheets.CellTypes.Base();
/**
* 创建一个input输入框
* @returns {HTMLInputElement}
*/
NumberCellType.prototype.createEditorElement = function (sheet) {
var input = document.createElement("input");
input.setAttribute('data-col', sheet.col);
input.setAttribute('data-row', sheet.row);
return input;
};
/**
* 初始化事件
* @param editorContext
* @param cellStyle
* @param cellRect
*/
NumberCellType.prototype.activateEditor = function (editorContext, cellStyle, cellRect) {
var self = this;
//Initialize input editor.
if (editorContext) {
var $editor = $(editorContext);
GC.Spread.Sheets.CellTypes.Base.prototype.activateEditor.apply(this, arguments);
$editor.css("position", "absolute");
var numType = this.numType;
$editor.on('input change', function (e) { //对输入的值进行搜索
var value = $editor.val();
var aNew = value;
var DecimalPlaces = numType.DecimalPlaces
var re1 = /[^(\d.)+/g;
var re2 = /(?<=\..*?|^)\./g
var re3 = new RegExp("([0-9]+\.[0-9]{" + DecimalPlaces + "})[0-9]*");
re1.test("ssss");
aNew = aNew.replace(re1, "");
aNew = aNew.replace(re2, "");
aNew = aNew.replace(re3, "$1");
$editor.val(aNew)
});
}
}
/**
* 隐藏提示框
* @param editorContext
*/
NumberCellType.prototype.deactivateEditor = function (editorContext) {
//Remove input editor when end editor status.
if (editorContext) {
}
GC.Spread.Sheets.CellTypes.Base.prototype.deactivateEditor.apply(this, arguments)
};
NumberCellType.prototype.setEditorValue = function (editor, value) {
if (value) {
$(editor).val(value);
}
};
NumberCellType.prototype.getEditorValue = function (editor) {
var $editor = $(editor);
var value = $editor.val();
return value;
};
NumberCellType.prototype.updateEditor = function (editorContext, cellStyle, cellRect) {
if (editorContext) {
var $editor = $(editorContext);
$editor.css("width", cellRect.width);
$editor.css("height", cellRect.height);
}
}
|