找回密码
 立即注册

QQ登录

只需一步,快速开始

a931520261

注册会员

5

主题

13

帖子

48

积分

注册会员

积分
48

微信认证勋章

最新发帖
a931520261
注册会员   /  发表于:2018-12-10 16:47  /   查看:2873  /  回复:3
目前使用的版本是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? 而不需要继续采用这种编程实现的方式。


3 个回复

倒序浏览
KevinChen讲师达人认证 悬赏达人认证 SpreadJS 开发认证
论坛元老   /  发表于:2018-12-10 17:38:24
沙发
您好,看您的代码,您是想实现一个列头checkbox,点击后全选所有的列checkbox。

类似的功能,SpreadJS提供了一个分组列的功能,请参考学习指南:

https://demo.grapecity.com.cn/Sp ... demos/outlineColumn
回复 使用道具 举报
a931520261
注册会员   /  发表于:2018-12-11 10:11:11
板凳
KevinChen 发表于 2018-12-10 17:38
您好,看您的代码,您是想实现一个列头checkbox,点击后全选所有的列checkbox。

类似的功能,SpreadJS提 ...

好的, 我看看
回复 使用道具 举报
KevinChen讲师达人认证 悬赏达人认证 SpreadJS 开发认证
论坛元老   /  发表于:2018-12-11 11:08:13
地板

好的
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 立即注册
返回顶部