请选择 进入手机版 | 继续访问电脑版
 找回密码
 立即注册

QQ登录

只需一步,快速开始

aaaaaaaaaaaaa

注册会员

1

主题

2

帖子

17

积分

注册会员

积分
17
  • 46

    金币

  • 1

    主题

  • 2

    帖子

最新发帖
aaaaaaaaaaaaa
注册会员   /  发表于:2025-11-28 09:42  /   查看:60  /  回复:3
1金币
本帖最后由 Wilson.Zhang 于 2025-12-4 14:01 编辑

产品:SpreadJS
版本:18
调研编号:GCNSJS-28105
Last Review:2025-12-04
当前进展:调研中。

在甘特图中,怎么添加自定义的单元格类型。如上没有生效是什么问题?
  1. let view = myTable1.addView("ganttView", [
  2.     // { value: "innerId", caption: "innerId", width: 50,style:{vAlign:'center',hAlign:'center'}},
  3.     { value: "taskNumber", caption: "NO", width: 50, style: { vAlign: 'center', hAlign: 'center' } },
  4.     { value: "name", caption: "Task Name", width: "3*", required: true, style: { wordWrap: true } },
  5.     { value: "duration", caption: "Duration", width: 90 },
  6.     { value: "start", caption: "startTime", width: 200 },
  7.     { value: "finishTime", caption: "finishTime", width: 200 },
  8.     { value: "predecessors", caption: "Predecessors", width: 50 },
  9.     {
  10.         value: "result", caption: "Result",
  11.         style: {
  12.             cellType: cellType2
  13.         }
  14.     },
  15.     {
  16.         value: "aaa",
  17.         caption: "aaa",
  18.         style: {
  19.             cellType: new MySelector() // 自定义的
  20.         }
  21.     },
  22.     {
  23.         value: "person", caption: "person", width: 200,
  24.         style: {
  25.             dropDowns: [{
  26.                 type: GC.Spread.Sheets.DropDownType.list,
  27.                 option: {
  28.                     items: [{ text: '选项1', value: '1' }, { text: '选项2', value: '2' }, { text: '选项3', value: '3' }],
  29.                     multiSelect: true
  30.                 }
  31.             }],
  32.             cellButtons: [{
  33.                 imageType: GC.Spread.Sheets.ButtonImageType.dropdown,
  34.                 command: 'openList',
  35.                 useButtonStyle: false,
  36.                 hoverBackColor: '#E2F3FE',
  37.             }
  38.             ]
  39.         }
  40.     }
  41. ]);

  42. ========================== MySelector ==========================
  43. import * as GC from "@grapecity-software/spread-sheets";
  44. function MySelector() {
  45.     this.typeName = 'MySelector';
  46. }

  47. MySelector.prototype = new GC.Spread.Sheets.CellTypes.Base();
  48. MySelector.prototype.paint = function (ctx, value, x, y, w, h, style, options) {
  49.     if (value) {
  50.         console.log('paint, value: ', value);
  51.     }
  52.     GC.Spread.Sheets.CellTypes.Base.prototype.paint.apply(this, [ctx, value.value, x, y, w, h, style, options]);
  53. }
  54. MySelector.prototype.updateEditor = function (editorContext, cellStyle, cellRect) {
  55.     console.log('updateEditor: ', editorContext);
  56.     if (editorContext) {
  57.         editorContext.style.width = cellRect.width + 'px';
  58.         editorContext.style.height = 200;
  59.         return { height: 200 };
  60.     }
  61. }
  62. MySelector.prototype.createEditorElement = function () {
  63.     console.log("======= createEditorElement =======");
  64.     console.log('this.typeName: ', this.typeName);
  65.     //  容器以排布输入框和选择器
  66.     var container = document.createElement('div');
  67.     container.setAttribute('gcUIElement', 'gcEditingInput');
  68.     container.setAttribute('id', 'MySelector');
  69.     container.style.backgroundColor = 'white';
  70.     container.style.overflow = 'hidden';
  71.     container.style.display = 'flex';
  72.     container.style.minHeight = "200px"
  73.     container.style.flexDirection = 'column';

  74.     //  输入框,显示或输入检索数据
  75.     var searchInput = document.createElement('input');
  76.     searchInput.placeholder = '请输入';
  77.     container.appendChild(searchInput);

  78.     //  选择器,列举各选项
  79.     var list = document.createElement('select');
  80.     list.multiple = true;
  81.     // list.overflow = 'auto';
  82.     var listItems = [
  83.         { text: '苹果', value: 'apple' },
  84.         { text: '香蕉', value: 'banana' },
  85.         { text: '橙子', value: 'orange' },
  86.         { text: '樱桃', value: 'cherry' },
  87.         { text: '西瓜', value: 'watermelon' },
  88.         { text: '葡萄', value: 'grape' },
  89.         { text: '桃子', value: 'peach' },
  90.         { text: '其他水果', value: 'ogan' }
  91.     ];
  92.     listItems.forEach(item => {
  93.         var listItem = document.createElement('option');
  94.         listItem.textContent = item.text;
  95.         listItem.value = item.value;
  96.         list.appendChild(listItem);
  97.     })
  98.     list.style.flex = "1"
  99.     list.style.minHeight = '100px';
  100.     container.appendChild(list);

  101.     // 输入框输入事件处理,实现模糊搜索
  102.     searchInput.addEventListener('input', function () {
  103.         const searchValue = this.value.toLowerCase();
  104.         console.log('search value: ', searchValue);
  105.         const options = list.options;
  106.         console.log('options: ', options);
  107.         for (let i = 0; i < options.length; i++) {
  108.             const optionText = options.textContent.toLowerCase();
  109.             if (optionText.includes(searchValue)) {
  110.                 console.log('included: ', optionText, ', ', searchValue);
  111.                 options.style.display = 'block';
  112.             } else {
  113.                 options.style.display = 'none';
  114.             }
  115.         }
  116.     });

  117.     list.addEventListener('change', function () {
  118.         const selectedOptions = Array.from(this.selectedOptions);
  119.         const selectedTexts = [];
  120.         console.log('...selectedOptions: ', selectedOptions);
  121.         selectedOptions.forEach(option => {
  122.             const item = document.createElement('span');
  123.             item.textContent = option.textContent;
  124.             selectedTexts.push(option.value);
  125.         });
  126.         console.log('selectedTexts: ', selectedTexts);
  127.         searchInput.value = selectedTexts.join(', ');
  128.     });

  129.     return container;
  130. }
  131. MySelector.prototype.getEditorValue = function (editorContext) {
  132.     console.log('getEditorValue: ', editorContext);
  133.     console.log('getEditorValue, value: ', editorContext.children[0].value);

  134.     return { value: editorContext.children[0].value };
  135. }
  136. MySelector.prototype.setEditorValue = function (editorContext, value) {
  137.     console.log('setEditorValue: ', editorContext, ', value: ', value);
  138.     editorContext.children[0].value = value ? value.value : null;
  139.     //  获取input输入框中的数据,对被选中项设置selected属性为true
  140.     if (value && value.value) {
  141.         var inputContent = value.value.split(', ');
  142.         console.log('input content: ', inputContent);
  143.         var selectList = editorContext.children[1];
  144.         Array.from(selectList.options).forEach(item => {
  145.             if (inputContent.includes(item.value)) {
  146.                 item.selected = true;
  147.             }
  148.         });
  149.     }
  150. }
  151. MySelector.prototype.isReservedKey = function (e) {
  152.     return (e.keyCode === GC.Spread.Commands.Key.tab && !e.ctrlKey && !e.shiftKey && !e.altKey);
  153. }

  154. export default MySelector;
复制代码




3 个回复

Matthew.Xue
超级版主   /  发表于:2025-11-28 11:44:05
沙发
本帖最后由 Matthew.Xue 于 2025-11-28 15:54 编辑

您好,甘特图列具体支持的属性可以参考如下文档:
https://demo.grapecity.com.cn/sp ... C.Data#styleoptions
关于自定义单元格是否支持,目前仍需调研,请耐心等待
回复 使用道具 举报
aaaaaaaaaaaaa
注册会员   /  发表于:2025-11-28 13:42:47
板凳
Matthew.Xue 发表于 2025-11-28 11:44
您好,甘特图的列不支持设置cellType,具体支持的属性可以参考如下文档:
https://demo.grapecity.com.cn/ ...

那该怎么自定义这种类型呢?
回复 使用道具 举报
Matthew.Xue
超级版主   /  发表于:2025-11-28 15:54:33
地板
aaaaaaaaaaaaa 发表于 2025-11-28 13:42
那该怎么自定义这种类型呢?

请耐心等待,我还需要调研一下这个问题,有结果了会和您及时同步
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 立即注册
返回顶部