测试出来了,数据源不变的情况下,调整Columni的tems位置,设置的默认值就不对了
没有调位置之前-正常
调了位置之后-视图的数据就变了-不正确
测试代码
- import * as React from 'react';
- import * as ReactDOM from 'react-dom';
- import '@grapecity/spread-sheets-resources-zh';
- GC.Spread.Common.CultureManager.culture("zh-cn");
- import GC from '@grapecity/spread-sheets';
- import { SpreadSheets } from '@grapecity/spread-sheets-react';
- import './styles.css';
- const Component = React.Component;
- const GCsheets = GC.Spread.Sheets;
- function _getElementById(id) {
- return document.getElementById(id);
- }
- class App extends Component {
- constructor(props) {
- super(props);
- this.spread = null;
- this.table = null;
- this.state = {
- dirtyRowsValue: null
- };
- }
- render() {
- return (
- <div class="sample-tutorial">
- <div class="sample-spreadsheets">
- <SpreadSheets workbookInitialized={spread=>this.initSpread(spread)}>
- </SpreadSheets>
- </div>
- <input onClick={()=>this.addTable(this.spread)} type="button" value='添加'></input>
- </div>
- );
- }
- initSpread(spread) {
- this.spread = spread;
-
- }
- addTable(spread){
- spread.suspendPaint();
- let sheet = spread.getActiveSheet();
- let data = {
- name: 'Jones', region: 'East',
- cost: [
- {
- name: "面积",
- disable_edit_amount: 0,
- can_del: 0,
- cost_type: 1
- }, {
- name: "套内价格",
- disable_edit_amount: 0,
- can_del: 0,
- cost_type: 0
- }, {
- name: "套外价格",
- disable_edit_amount: 0,
- can_del: 0,
- cost_type: 0
- }, {
- name: "基础装修",
- disable_edit_amount: 0,
- can_del: 0,
- cost_type: 0
- }, {
- name: "管理费",
- disable_edit_amount: 0,
- can_del: 0,
- cost_type: 0
- }, {
- name: "税金",
- disable_edit_amount: 0,
- can_del: 0,
- cost_type: 0
- }, {
- name: "总报价",
- disable_edit_amount: 0,
- can_del: 1,
- cost_type: 1
- }]
- };
- let table = sheet.tables.add('tableSales', 0, 0, 5, 4);
- this.table = table;
- const column=[
- {dataIndex:'name',title:'名称'},
- {dataIndex:'can_del',title:'是否能删除',columnType:{
- type:'select',
- options:[{text: '否', value: 0},{text: '是', value: 1}]
- }
- },{dataIndex:'disable_edit_amount',title:'是否能编辑',columnType:{
- type:'select',
- // options:[{text: '是', value: 1},{text: '否', value: 0}] //(有问题) 把这个注释打开就能重现
- options:[{text: '否', value: 0},{text: '是', value: 1}]//(正常)
- }
- },{dataIndex:'cost_type',title:'是否是合计项',columnType:{
- type:'select',
- options:[{text: '否', value: 0},{text: '是', value: 1}]
- }
- }]
- table.style(GCsheets.Tables.TableThemes["medium4"]);
- table.autoGenerateColumns(false);
- let newColumn=this.setTableColumn(sheet,column,0)
- table.bind(newColumn, 'cost', data);
- spread.resumePaint();
- }
- //统一初始化话column
- setTableColumn(sheet, column, start) {
- if (!column.length) return;
- let tableColumns = []
- for (let i = 0, IL = column.length; i < IL; i++) {
- let tableColumn = new GCsheets.Tables.TableColumn(i + 1, column[i].dataIndex, column[i].title || '', column[i].formatter || null);
- if (column[i].columnType) {
- const columnType = column[i].columnType;
- if (columnType.type === 'select' && (columnType.options || []).length) {
- const combo = new GCsheets.CellTypes.ComboBox();
- combo.items(columnType.options);
- combo.editorValueType(GCsheets.CellTypes.EditorValueType.index);
- tableColumn = new GCsheets.Tables.TableColumn(i + 1, column[i].dataIndex, column[i].title || '', column[i].formatter || null, combo)
- }
- }
- sheet.setColumnWidth(start + i, column[i].width || 80);//设置宽度
- tableColumns.push(tableColumn);
- }
- return tableColumns
- }
- }
- ReactDOM.render(<App />, _getElementById('app'));
复制代码
|