找回密码
 立即注册

QQ登录

只需一步,快速开始

Clark.Pan 讲师达人认证 悬赏达人认证 SpreadJS 开发认证
超级版主   /  发表于:2022-5-4 12:22  /   查看:1957  /  回复:0
背景:
通过cellbuttons功能在同一个单元格上设置多个自定制按钮,每个按钮点击后可以触发不同的事件。常见于grid表格中的操作列,常用于对改行数据进行增删改查操作。
核心代码:
通过cellbuttons设置单元格上的列表按钮,代码中的图片采用了base64的编码便于序列化操作。
  1.    let style = new GC.Spread.Sheets.Style();
  2.                         style.cellButtons= [{
  3.                                         imageType: GC.Spread.Sheets.ButtonImageType.custom,
  4.                                         imageSrc: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAYAAABXAvmHAAABPklEQVR4Ae2YAWYDQRSGV6BUabFQiKE28wA9Qo7Qo/QIBRTQGyQESlUWURRSVdZssL3B5gZJT/A6A8Eq8qck//I+foDxvjWzfi8zuhiGYRg6yZxOs3lMG6N7ZsI0/AYYnEoiCZT44EQSwNfnlEgDkKSNmacrDQuQZQNIUApoepeQAGHavguoCewyG6i+5apfN6q1HDm+0ZWM/yewHKbDTpswujtM4PUiHUAgIO1hAu/XHAIpjThc4NP1XKAWmuBX6PmMSeADFygviQT8Ey6wyHkEVv4eF1gOiQRkjAtUBY9A464wgdmAZ/gga7xKvJzT/4F20D/gIA+IAEGFAIpcgr5C1MUtLsBcIbpQV4jgv/fZzG15K4RM8dXiIud/wB0BF7OlqxDBl9CGOqaMWZ+8QlTFj1ajx7/qg2EYhmH8AtrSH2QJmV2LAAAAAElFTkSuQmCC",
  5.                                         imageSize: {
  6.                                                 height: 20,
  7.                                                 width: 20
  8.                                         },
  9.                                         hoverBackColor: "#3390FF", // customize the hover backColor
  10.                                         buttonBackColor: "#82BC00", // customize the button backColor
  11.                                         command: (sheet, row, col, option) => {
  12.                                                 alert("do something you want to do 1");
  13.                                         },
  14.                                         position: GC.Spread.Sheets.ButtonPosition.left
  15.                                 },{
  16.                                         imageType: GC.Spread.Sheets.ButtonImageType.custom,
  17.                                         imageSrc: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAMgAAADICAYAAACtWK6eAAAAAXNSR0IArs4c6QAAFm5JREFUeF7tXWtsXMd1/ube3bvc5ZKiSEpKUrdVEkq2aVtwoAKFC6Qw2h99IC3aogwSJEVRpHDRBjasWH4odetVHMuxa9mu3TiIE6Ao0B+F3X/90RYBGgcF6qKNAlU2KT9o1wFU23qQJs3lLvfu7j3FXIoWRe3d+5r7PgQMGNiZOed853yaO3NmzgjwHyPACDgiIBgbRoARcEaACcLRwQgMQYAJwuHBCDBBOAYYgWAI8AwSDDfuVRAEmCAxOXruBdLn56GbyxC9Kdi4f3wVwty1+f/dJkRvdPP/5V9pHVSug+T/n18FlXZt/n9pCWRMghYEemgIKyb1CyuGCaLY9bc3qPQOUKoRSoZAqbWGUklDicpXgl+VSB2weoSeaaFX76PX6qC3+D56eFH0Vcko+jhMkBARMDdH+svXwZgmVJpVlMsCpRDDKesquqCehZ41BhOT6Cwuo8uzTTB4mSA+cJOzQ2cV5fMGDE2DkRZCeDGh30FX6Oh0aui+A5hMGC+oQf20701sRloRieu+hpF9BozVjBHCDWEimL0KulhCZ/FZ0XFrX9TfeQYZ4PmZZ6hi/R9G6lVUuib0vAdHl9DT+9jQq+gsHBdm3u31Yx8T5DJasw+RYS5jBHVUsvTp5MfZXtrKmUUz0NkrsPFSQ/S89Mlzm2ITZI702VlUe02M6BWU8+zoILZJoowAG6caaAPC3mYu2l8hCSIX2+eWUBsZQ7UPaEVzul975SdYrYvWmTraRVvcF4ogh79L5Q/eRm3EQjWKvITfwMta+7KJfm8UrYUFtIuSaykEQWbupEp9CtWOiWrWgjKN+soE5cYa2tdNoZX3dUquCSKJUR1FradhJI2BlnWdZEJyQ0P756pYzytR8kmQBmkzQL1sYjTrQZgF/eWMoplonnlCrGdBXz865o4ghxtUszoY3UjJsQ8/zsh6Wzv52EQzT4nH3BBE**N/0WdP6eSp1nXwPoi0MzDjlf2CUIkrr8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osEromRZ661309q2jd+p59ABBsdubY4E8g8Tt3AZpmIe4/SaICwTNXIboTUFMAVq3CdEbhSitg8p10BJglZZAxiRor4D10jwIL8CCYBLE5TYmSFxIs5xMIsAEyaTbWOm4EGCCxIU0y8kkAkyQTLqNlY4LASZIXEiznEwi8P/24b1B8ysNMwAAAABJRU5ErkJggg==",
  18.                                         imageSize: {
  19.                                                 height: 20,
  20.                                                 width: 20
  21.                                         },
  22.                                         command: (sheet, row, col, option) => {
  23.                                                 alert("do something you want to do 2");
  24.                                         },
  25.                                         position: GC.Spread.Sheets.ButtonPosition.left
  26.                         }];
复制代码

由于cellbuttons属于style,故可以通过style进行整列设置,或者使用namedStyle方便后续多次设置。

  1. sheet.setStyle(-1, 1, style);
复制代码
效果如下所示,第二列整列设置了按钮列表,点击不同的按钮触发不同的效果
image.png216773680.png
完整的demo见附件

mutipHyperLinkPicture2.html

10.36 KB, 下载次数: 75

0 个回复

您需要登录后才可以回帖 登录 | 立即注册
返回顶部