Spreadjs9使我们经常用到的一种表格插件,而当前插件没有现成的悬浮的属性,网上也有很多扩充悬浮属性的方法,但相关方法经常会有一些性能问题(因悬浮方法是单独设置)以及和原有属性冲突的情况,如下代码段可解决这个问题
1.首先重新定义悬浮的特性
想要悬浮和哪一种单元格属性共存则重写那种属性 TextCellType
`function TextCellType() {
//基础按钮 方法重置
GcSpread.Sheets.TextCellType.prototype.getHitInfo = function (x, y, cellStyle, cellRect, context) {
return {
x: window.event.clientX,//x//对于 行列位置处理
y: window.event.clientY,//y
row: context.row,
col: context.col,
cellStyle: cellStyle,
cellRect: cellRect,
sheetArea: context.sheetArea
};
};
GcSpread.Sheets.TextCellType.prototype.processMouseEnter = function (hitinfo) {
var ActiveSheet = BBGridSpread.getActiveSheet();
if (this._toolTipElement) {
try {
document.body.removeChild(this._toolTipElement);
}
catch (e) { }
this._toolTipElement = null;
}
if ($("#TipID")[0] != undefined) {
try {
document.body.removeChild($("#TipID")[0]);
} catch (e) {
}
this._toolTipElement = null;
}
var tips = "提示信息6666";
if (tips == undefined || tips == "") {
return;
}
if (!this._toolTipElement) {
var div = document.createElement("div");
div.id = "TipID";
$(div).css("position", "absolute")
.css("border", "1px #C0C0C0 solid")
.css("box-shadow", "1px 2px 5px rgba(0,0,0,0.4)")
.css("font", "9pt Arial")
.css("background", "white")
.css("padding", 5);
this._toolTipElement = div;
}
$(this._toolTipElement).html(tips)
.css("top", hitinfo.y)
.css("left", hitinfo.x);
$(this._toolTipElement).hide();
document.body.insertBefore(this._toolTipElement, null);
$(this._toolTipElement).show("fast");
};
GcSpread.Sheets.TextCellType.prototype.processMouseLeave = function (hitinfo) {
if (this._toolTipElement) {
try {
document.body.removeChild(this._toolTipElement);
} catch (e) {
}
this._toolTipElement = null;
}
if ($("#TipID")[0] != undefined) {
try {
document.body.removeChild($("#TipID")[0]);
} catch (e) {
}
this._toolTipElement = null;
}
};
}`
2.解决性能问题
如上重新定义后,即可批量设置悬浮属性
function Tips() {
var ActiveSheet;//当前活动sheet页
var JSON = ActiveSheet.toJSON();//转换为对象
var ATips = {};//此处准备相关的需要浮动显示的坐标
ATips["1_2"] = "22222";
ATips["2_2"] = "22222";
ATips["3_2"] = "22222";
//TextCellType 绑定划入划出方法
TextCellType();
//给单元格增加相关信息
for (var i = 0; i < JSON.rowCount; i++) {
for (var j = 0; j < JSON.columnCount; j++) {
if (ATips[i + "_" + j] != undefined) {
JSON.data.dataTable[i][j].style.cellType = new GcSpread.Sheets.TextCellType();
}
}
}
ActiveSheet.fromJSON(JSON);
}
批量执行,提高性能
同时解决下拉共存和性能问题