找回密码
 立即注册

QQ登录

只需一步,快速开始

云智装
金牌服务用户   /  发表于:2021-11-25 10:34  /   查看:5519  /  回复:15
1金币
本帖最后由 Lynn.Dou 于 2021-11-29 14:22 编辑
  1.       this.spread = spread;
  2.         spread.suspendPaint();
  3.         let sheet = spread.getActiveSheet();

  4.         let data = {
  5.             name: 'Jones', region: 'East',
  6.             sales: [
  7.                 {orderDate: '1/6/2013', item: 'Pencil', units: 95, cost: 1.99, isDelivered: '是'},
  8.                 {orderDate: '4/1/2013', item: 'Binder', units: 60, cost: 4.99, isDelivered: ''},
  9.                 {orderDate: '6/8/2013', item: 'Pen Set', units: 16, cost: 15.99, isDelivered: ''}
  10.             ]
  11.         };
  12.         let convert = function (item) {
  13.             return item['cost'] + '[backcolor=rgb(247, 247, 247)]tableColumn5.cellType(combo).value('是');设置不起作用[/backcolor]
  14. ;
  15.         }
  16.         let table = sheet.tables.add('tableSales', 0, 0, 5, 5);
  17.         this.table = table;
  18.         table.style(GCsheets.Tables.TableThemes["medium4"]);
  19.         let tableColumn1 = new GCsheets.Tables.TableColumn(1, "orderDate", "Order Date", "yyyy-mm-dd");
  20.         let tableColumn2 = new GCsheets.Tables.TableColumn(2, "item", "Item");
  21.         let tableColumn3 = new GCsheets.Tables.TableColumn(3, "units", "Units");
  22.         let tableColumn4 = new GCsheets.Tables.TableColumn(4, "cost", "Cost", null, null, convert);
  23.         let tableColumn5 = new GCsheets.Tables.TableColumn(5);
  24.         const combo = new GCsheets.CellTypes.ComboBox();
  25.         combo.items([{text: '是', value: 1},{text: '否', value: 0}])
  26.         tableColumn5.cellType(combo).value('是');
  27.         tableColumn5.name('选择');
  28.         table.autoGenerateColumns(false);
  29.         table.bind([tableColumn1, tableColumn2, tableColumn3, tableColumn4, tableColumn5], 'sales', data);
  30.         sheet.setColumnWidth(0, 120);
  31.         sheet.setColumnWidth(1, 120);
  32.         sheet.setColumnWidth(2, 120);
  33.         sheet.setColumnWidth(3, 120);
  34.         sheet.setColumnWidth(4, 120);
  35.         spread.resumePaint();
  36.     }
复制代码
tableColumn5.cellType(combo).value('是');设置不起作用

15 个回复

正序浏览
Lynn.Dou讲师达人认证 悬赏达人认证 SpreadJS 开发认证
超级版主   /  发表于:2021-11-29 16:16:46
16#
经调研,原因如下图:
image.png612072753.png

combo.editorValueType(GCsheets.CellTypes.EditorValueType.index);

修改为
combo.editorValueType(GCsheets.CellTypes.EditorValueType.value);
即可。

回复 使用道具 举报
Lynn.Dou讲师达人认证 悬赏达人认证 SpreadJS 开发认证
超级版主   /  发表于:2021-11-29 14:22:31
15#
回复 使用道具 举报
云智装
金牌服务用户   /  发表于:2021-11-29 14:11:26
14#
Lynn.Dou 发表于 2021-11-29 14:00
问题已复现,已将此问题记录下来,待有进展会在贴中更新。
本帖先做保留处理。

好的
回复 使用道具 举报
Lynn.Dou讲师达人认证 悬赏达人认证 SpreadJS 开发认证
超级版主   /  发表于:2021-11-29 14:00:31
13#
问题已复现,已将此问题记录下来,待有进展会在贴中更新。
本帖先做保留处理。
回复 使用道具 举报
云智装
金牌服务用户   /  发表于:2021-11-29 12:15:50
12#
Lynn.Dou 发表于 2021-11-25 17:43
在demo中添加下面代码,设置editorValueType 为value。(具体介绍请参考学习指南:https://demo.grapecity. ...

测试出来了,数据源不变的情况下,调整Columni的tems位置,设置的默认值就不对了
没有调位置之前-正常 image.png510800780.png
调了位置之后-视图的数据就变了-不正确
image.png268799437.png
测试代码
  1. import * as React from 'react';
  2. import * as ReactDOM from 'react-dom';
  3. import '@grapecity/spread-sheets-resources-zh';
  4. GC.Spread.Common.CultureManager.culture("zh-cn");
  5. import GC from '@grapecity/spread-sheets';
  6. import { SpreadSheets } from '@grapecity/spread-sheets-react';
  7. import './styles.css';

  8. const Component = React.Component;
  9. const GCsheets = GC.Spread.Sheets;

  10. function _getElementById(id) {
  11.     return document.getElementById(id);
  12. }

  13. class App extends Component {
  14.     constructor(props) {
  15.         super(props);
  16.         this.spread = null;
  17.         this.table = null;
  18.         this.state = {
  19.             dirtyRowsValue: null
  20.         };
  21.     }
  22.     render() {
  23.         return (
  24.             <div class="sample-tutorial">
  25.                 <div class="sample-spreadsheets">
  26.                     <SpreadSheets workbookInitialized={spread=>this.initSpread(spread)}>
  27.                     </SpreadSheets>
  28.                 </div>
  29.                 <input onClick={()=>this.addTable(this.spread)} type="button" value='添加'></input>
  30.             </div>
  31.         );
  32.     }
  33.     initSpread(spread) {
  34.         this.spread = spread;
  35.         
  36.     }
  37.     addTable(spread){
  38.         spread.suspendPaint();
  39.         let sheet = spread.getActiveSheet();
  40.         let data = {
  41.             name: 'Jones', region: 'East',
  42.             cost: [
  43.                     {
  44.                         name: "面积",
  45.                         disable_edit_amount: 0,
  46.                         can_del: 0,
  47.                         cost_type: 1
  48.                     }, {
  49.                         name: "套内价格",
  50.                         disable_edit_amount: 0,
  51.                         can_del: 0,
  52.                         cost_type: 0
  53.                     }, {
  54.                         name: "套外价格",
  55.                         disable_edit_amount: 0,
  56.                         can_del: 0,
  57.                         cost_type: 0
  58.                     }, {
  59.                         name: "基础装修",
  60.                         disable_edit_amount: 0,
  61.                         can_del: 0,
  62.                         cost_type: 0
  63.                     }, {
  64.                         name: "管理费",
  65.                         disable_edit_amount: 0,
  66.                         can_del: 0,
  67.                         cost_type: 0
  68.                     }, {
  69.                         name: "税金",
  70.                         disable_edit_amount: 0,
  71.                         can_del: 0,
  72.                         cost_type: 0
  73.                     }, {
  74.                         name: "总报价",
  75.                         disable_edit_amount: 0,
  76.                         can_del: 1,
  77.                         cost_type: 1
  78.                     }]
  79.         };
  80.         let table = sheet.tables.add('tableSales', 0, 0, 5, 4);
  81.         this.table = table;
  82.         const column=[
  83.             {dataIndex:'name',title:'名称'},
  84.             {dataIndex:'can_del',title:'是否能删除',columnType:{
  85.             type:'select',
  86.             options:[{text: '否', value: 0},{text: '是', value: 1}]
  87.         }
  88.         },{dataIndex:'disable_edit_amount',title:'是否能编辑',columnType:{
  89.             type:'select',
  90.             // options:[{text: '是', value: 1},{text: '否', value: 0}] //(有问题) 把这个注释打开就能重现
  91.             options:[{text: '否', value: 0},{text: '是', value: 1}]//(正常)
  92.         }
  93.         },{dataIndex:'cost_type',title:'是否是合计项',columnType:{
  94.             type:'select',
  95.             options:[{text: '否', value: 0},{text: '是', value: 1}]
  96.         }
  97.         }]
  98.         table.style(GCsheets.Tables.TableThemes["medium4"]);
  99.         table.autoGenerateColumns(false);
  100.         let newColumn=this.setTableColumn(sheet,column,0)
  101.         table.bind(newColumn, 'cost', data);
  102.         spread.resumePaint();
  103.     }
  104.     //统一初始化话column
  105.     setTableColumn(sheet, column, start) {
  106.     if (!column.length) return;
  107.     let tableColumns = []
  108.     for (let i = 0, IL = column.length; i < IL; i++) {
  109.       let tableColumn = new GCsheets.Tables.TableColumn(i + 1, column[i].dataIndex, column[i].title || '', column[i].formatter || null);
  110.       if (column[i].columnType) {
  111.         const columnType = column[i].columnType;
  112.         if (columnType.type === 'select' && (columnType.options || []).length) {
  113.           const combo = new GCsheets.CellTypes.ComboBox();
  114.           combo.items(columnType.options);
  115.           combo.editorValueType(GCsheets.CellTypes.EditorValueType.index);
  116.           tableColumn = new GCsheets.Tables.TableColumn(i + 1, column[i].dataIndex, column[i].title || '', column[i].formatter || null, combo)
  117.         }
  118.       }
  119.       sheet.setColumnWidth(start + i, column[i].width || 80);//设置宽度
  120.       tableColumns.push(tableColumn);
  121.     }
  122.     return tableColumns
  123.   }

  124. }


  125. ReactDOM.render(<App />, _getElementById('app'));
复制代码


回复 使用道具 举报
Lynn.Dou讲师达人认证 悬赏达人认证 SpreadJS 开发认证
超级版主   /  发表于:2021-11-25 17:43:10
11#
在demo中添加下面代码,设置editorValueType 为value。(具体介绍请参考学习指南:https://demo.grapecity.com.cn/sp ... pes/combobox/purejs
  1. combo.editorValueType(GC.Spread.Sheets.CellTypes.EditorValueType.value);
复制代码

修改后代码如下图所示:
image.png832744140.png
image.png840387878.png

完整代码见附件。

demo-sjs模板.html

4.56 KB, 下载次数: 352

回复 使用道具 举报
云智装
金牌服务用户   /  发表于:2021-11-25 17:26:10
10#
Lynn.Dou 发表于 2021-11-25 15:44
修改不了值 指的是 不能选择下拉项来赋值吗?如果是,参考下方附件这个demo。

如果不是,请详细描述您当 ...

image.png265325011.png
换位置后显示“是”
回复 使用道具 举报
云智装
金牌服务用户   /  发表于:2021-11-25 17:23:20
9#
Lynn.Dou 发表于 2021-11-25 15:44
修改不了值 指的是 不能选择下拉项来赋值吗?如果是,参考下方附件这个demo。

如果不是,请详细描述您当 ...

我测试了你的demo也不行 image.png432429808.png
默认应该是 “是”的
回复 使用道具 举报
Lynn.Dou讲师达人认证 悬赏达人认证 SpreadJS 开发认证
超级版主   /  发表于:2021-11-25 15:44:52
8#
修改不了值 指的是 不能选择下拉项来赋值吗?如果是,参考下方附件这个demo。

如果不是,请详细描述您当前遇到得问题以及您得需求。

demo-sjs模板.html

4.49 KB, 下载次数: 468

回复 使用道具 举报
云智装
金牌服务用户   /  发表于:2021-11-25 15:10:27
7#
Lynn.Dou 发表于 2021-11-25 14:01
有问题欢迎另开新帖交流。

刚测了下,值能设置了,但是修改不了 image.png984772949.png


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