本帖最后由 寒梅落尽 于 2018-1-15 16:59 编辑
现在需要实现一个批量删除功能,通过在首列添加一列复选框来标记选中数据,我再论坛找到的demo写在我的代码里,但是一直出错,能不能帮看下,下面是代码和错误原因
function AddCheckBox(spread) {
var spreadNS = GC.Spread.Sheets;
var sheet = spread.getSheet(0);
sheet.addColumns(0, 1);
sheet.suspendPaint();
var c = new spreadNS.CellTypes.CheckBox();
c.isThreeState(false);
c.textTrue("");
c.textFalse("");
sheet.setColumnWidth(0, 100);
sheet.setCellType(0, 0, new HeaderCheckBoxCellType(), GC.Spread.Sheets.SheetArea.colHeader);
for (var i = 0; i < spread.getSheet(0).getRowCount() ; i++) {
sheet.setCellType(i, 0, c);
c.textAlign(GC.Spread.Sheets.CellTypes.CheckBoxTextAlign.center);
}
sheet.resumePaint();
function setRowCheck(sheet, row) {
var checkedIndexList = getCheckedRowIndexList(sheet);
if (checkedIndexList.length === 0) {
sheet.setValue(row, 0, true, GcSpread.Sheets.SheetArea.rowHeader);
}
}
function setRangeCheck(sheet, row, rowCount) {
var checkedIndexList = getCheckedRowIndexList(sheet);
if (checkedIndexList.length === 0) {
sheet.isPaintSuspended(true)
for (var i = row; i < row + rowCount; i++) {
sheet.setValue(i, 0, true, GcSpread.Sheets.SheetArea.rowHeader);
}
sheet.isPaintSuspended(false)
}
}
function getCheckedRowIndexList(sheet) {
var indexList = [];
var rowCount = sheet.getRowCount();
for (var i = 0; i < rowCount; i++) {
var value = sheet.getValue(i, 0, GcSpread.Sheets.SheetArea.rowHeader);
if (value === true) {
indexList.push(i);
}
}
return indexList;
}
function getCheckedRowIndexListInRange(sheet, start, end) {
var indexList = [];
var rowCount = sheet.getRowCount();
for (var i = start; i < end; i++) {
var value = sheet.getValue(i, 0, GcSpread.Sheets.SheetArea.rowHeader);
if (value === true) {
indexList.push(i);
}
}
return indexList;
}
function HeaderCheckBoxCellType() {
}
HeaderCheckBoxCellType.prototype = new GC.Spread.Sheets.CheckBoxCellType();
HeaderCheckBoxCellType.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;
};
HeaderCheckBoxCellType.prototype.processMouseUp = function (hitInfo) {
var sheet = hitInfo.sheet, sheetArea = hitInfo.sheetArea,
row = hitInfo.row, col = hitInfo.col;
var value = !(sheet.getValue(row, col, sheetArea) || false);
sheet.setValue(row, col, value, sheetArea);
};
function getActualRange(range, maxRowCount, maxColCount) {
var row = range.row < 0 ? 0 : range.row;
var col = range.col < 0 ? 0 : range.col;
var rowCount = range.rowCount < 0 ? maxRowCount : range.rowCount;
var colCount = range.colCount < 0 ? maxColCount : range.colCount;
return new spreadNS.Range(row, col, rowCount, colCount);
}
sheet.bind(spreadNS.Events.SelectionChanged, function (e, args) {
debugger
var sheet = spread.getActiveSheet();
var sels = sheet.getSelections();
var selected = sels[0];
if (sels && sels.length > 0) {
if (selected.rowCount === 1) {
setRowCheck(sheet, selected.row)
}
else {
setRangeCheck(sheet, selected.row, selected.rowCount)
}
}
});
}
|
-
|