找回密码
 立即注册

QQ登录

只需一步,快速开始

Joestar.Xu SpreadJS 开发认证

超级版主

38

主题

6784

帖子

8856

积分

超级版主

Rank: 8Rank: 8

积分
8856

SpreadJS 认证SpreadJS 高级认证

Joestar.Xu SpreadJS 开发认证
超级版主   /  发表于:2023-8-30 16:03  /   查看:796  /  回复:0
在SpreadJS的设计器中可以在Ribbon上选择不同的表格样式:


image.png968579101.png

有用户提出如何能自定义实现一个跟这种菜单类似的效果呢?

这就需要用到list来实现了,具体的参考代码如下:

  1. window.onload = function () {
  2.   let designerConfig = JSON.parse(
  3.     JSON.stringify(GC.Spread.Sheets.Designer.DefaultConfig)
  4.   );

  5.   designerConfig.commandMap = {
  6.     menu: {
  7.       text: "菜单",
  8.       title: "菜单",
  9.       bigButton: "=ribbonHeight>toolbarHeight",
  10.       commandName: "menu",
  11.       direction: '=IF(ribbonHeight<toolbarHeight,"horizontal","vertical")',
  12.       dropdownListItemType: "menuitemradio",
  13.       // enableContext: "",
  14.       iconClass: "ribbon-button-formattable",
  15.     },
  16.     list: {
  17.       commandName: "list",
  18.       // enableContext: "",
  19.       execute(context, propertyName, checked) {
  20.         console.log("execute");
  21.         console.log(context);
  22.         console.log(propertyName);
  23.         console.log(checked);
  24.       },
  25.       getState(context, propertyName) {
  26.         console.log("getState");
  27.         console.log(context);
  28.         console.log(propertyName);
  29.       },
  30.       listContent: [
  31.         {
  32.           commandName: "list",
  33.           groupItems: [
  34.             {
  35.               iconClass: "table-format-light0",
  36.               iconHeight: 48,
  37.               iconWidth: 64,
  38.               tip: "Item1",
  39.               value: "light0",
  40.             },
  41.             {
  42.               iconClass: "table-format-light0",
  43.               iconHeight: 48,
  44.               iconWidth: 64,
  45.               tip: "Item1",
  46.               value: "light0",
  47.             },
  48.             {
  49.               iconClass: "table-format-light1",
  50.               iconHeight: 48,
  51.               iconWidth: 64,
  52.               tip: "Item1",
  53.               value: "light0",
  54.             },
  55.             {
  56.               iconClass: "table-format-light1",
  57.               iconHeight: 48,
  58.               iconWidth: 64,
  59.               tip: "Item1",
  60.               value: "light0",
  61.             },
  62.             {
  63.               iconClass: "table-format-light2",
  64.               iconHeight: 48,
  65.               iconWidth: 64,
  66.               tip: "Item1",
  67.               value: "light0",
  68.             },
  69.             {
  70.               iconClass: "table-format-light2",
  71.               iconHeight: 48,
  72.               iconWidth: 64,
  73.               tip: "Item1",
  74.               value: "light0",
  75.             },
  76.             {
  77.               iconClass: "table-format-light3",
  78.               iconHeight: 48,
  79.               iconWidth: 64,
  80.               tip: "Item1",
  81.               value: "light0",
  82.             },
  83.             {
  84.               iconClass: "table-format-light3",
  85.               iconHeight: 48,
  86.               iconWidth: 64,
  87.               tip: "Item1",
  88.               value: "light0",
  89.             },
  90.           ],
  91.           groupName: "List One",
  92.           wrap: false,
  93.         },
  94.       ],
  95.       maxWidth: 550,
  96.       type: "listContent",
  97.     },
  98.   };

  99.   designerConfig.ribbon[0].buttonGroups.push({
  100.     label: "测试",
  101.     thumbnailClass: "ribbon-thumbnail-styles",
  102.     commandGroup: {
  103.       children: [
  104.         {
  105.           children: ["list"],
  106.           command: "menu",
  107.           dropdownMaxWidth: 550,
  108.           type: "dropdown",
  109.         },
  110.       ],
  111.     },
  112.   });

  113.   let designer = new GC.Spread.Sheets.Designer.Designer(
  114.     "gc-designer-container",
  115.     designerConfig
  116.   );

  117.   let spread = designer.getWorkbook();
  118.   
  119.   let sheet = spread.getActiveSheet();
  120. };
复制代码


相似的效果都可以采用list来实现。
SpreadJS 17.0.8 | GcExcel 7.1.1 已发布~

0 个回复

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