目前使用的版本是v11,项目有全选所有行的需求,目前使用的代码是论坛里面搜到的v10版本的,如下:
/*
*checkboxFunction
*SpreadJS V10 列头全选框
*/
checkboxFunction = (spreadNS, spread) => {
var sheet = spread.getActiveSheet();
var MyCheckBoxCellType;
function MyCheckBoxCellType() {
spreadNS.CellTypes.CheckBox.apply(this);
this.caption("");
}
MyCheckBoxCellType.prototype = new spreadNS.CellTypes.CheckBox();
var basePaint = spreadNS.CellTypes.CheckBox.prototype.paint;
MyCheckBoxCellType.prototype.paint = function (ctx, value, x, y, width, height, style, context) {
//var tag = context.sheet.getColumn(context.col,context.sheetArea).tag();
var tag = context.sheet.getTag(context.row, context.col, context.sheetArea);
if (tag !== true) {
tag = false;
}
basePaint.apply(this, [ctx, tag, x, y, width, height, style, context]);
};
MyCheckBoxCellType.prototype.getHitInfo = function (x, y, cellStyle, cellRect, context) {
if (context) {
return {
x: x,
y: y,
row: context.row,
col: context.col,
cellRect: cellRect,
sheetArea: context.sheetArea,
isReservedLocation: true,
sheet: context.sheet
};
}
return null;
};
MyCheckBoxCellType.prototype.processMouseUp = function (hitInfo) {
var sheet = hitInfo.sheet,
row = hitInfo.row,
col = hitInfo.col,
sheetArea = hitInfo.sheetArea;
if (sheet.getCell(0, 0, spreadNS.SheetArea.colHeader).locked() && sheet.options.isProtected) {
}
var tag = sheet.getTag(row, col, sheetArea);
//var tag = sheet.getColumn(col,sheetArea).tag();
if (tag === undefined || tag === null) { //first time
sheet.setTag(row, col, true, sheetArea);
//sheet.getColumn(col,sheetArea).tag(true)
} else {
sheet.setTag(row, col, !tag, sheetArea);
//sheet.getColumn(col,sheetArea).tag(!tag)
}
//add your code here
tag = sheet.getTag(row, col, sheetArea);
//tag = sheet.getColumn(col,sheetArea).tag();
// sheet.setValue(-1, 0, tag);
sheet.suspendPaint();
for (var i = 0; i < sheet.getRowCount(); i++) {
var cell = sheet.getCell(i, col);
if (cell.cellType() instanceof spreadNS.CellTypes.CheckBox) {
cell.value(tag);
}
}
sheet.resumePaint();
}
sheet.setCellType(0, 0, new MyCheckBoxCellType(), spreadNS.SheetArea.colHeader);
spread.bind(spreadNS.Events.ButtonClicked,
function (e, args) {
var sheet = args.sheet,
row = args.row,
col = args.col;
var cellType = sheet.getCellType(row, col);
if (cellType instanceof spreadNS.CellTypes.CheckBox) {
var colHeaderCell = cellType = sheet.getCell(0, col, spreadNS.SheetArea.colHeader);
if (colHeaderCell.cellType() instanceof MyCheckBoxCellType) {
var checkStatus = true;
for (var i = 0; i < sheet.getRowCount(); i++) {
var cell = sheet.getCell(i, col);
if (cell.cellType() instanceof spreadNS.CellTypes.CheckBox && !cell.value()) {
checkStatus = false;
break;
}
}
colHeaderCell.tag(checkStatus);
sheet.repaint();
}
}
});
}
问题: 以上代码在v11中能够正常使用,但是 v11是否提供了更便捷的api? 而不需要继续采用这种编程实现的方式。
|
|