找回密码
 立即注册

QQ登录

只需一步,快速开始

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, 下载次数: 92

回复 使用道具 举报
云智装
金牌服务用户   /  发表于: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-29 14:00:31
13#
问题已复现,已将此问题记录下来,待有进展会在贴中更新。
本帖先做保留处理。
回复 使用道具 举报
云智装
金牌服务用户   /  发表于:2021-11-29 14:11:26
14#
Lynn.Dou 发表于 2021-11-29 14:00
问题已复现,已将此问题记录下来,待有进展会在贴中更新。
本帖先做保留处理。

好的
回复 使用道具 举报
Lynn.Dou讲师达人认证 悬赏达人认证 SpreadJS 开发认证
超级版主   /  发表于:2021-11-29 14:22:31
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);
即可。

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