本帖最后由 Clark.Pan 于 2021-8-2 14:31 编辑
异常出现步骤:
1. 使用的官网案例:https://demo.grapecity.com.cn/spreadjs/SpreadJSTutorial/features/pivot-table/pivot-panel/overview/react2. 在案例上加了两个SpreadSheets,每个spread都有自己的透视页
- <div class="sample-tutorial">
- <div class="sample-spreadsheets">
- <SpreadSheets workbookInitialized={spread=>this.initSpread(spread)}>
- <Worksheet>
- </Worksheet>
- <Worksheet>
- </Worksheet>
- </SpreadSheets>
- </div>
- <div class="sample-panel">
- <div id="panel"></div>
- </div>
- </div>
- <div class="sample-tutorial">
- <div class="sample-spreadsheets">
- <SpreadSheets workbookInitialized={spread=>this.initSpread(spread, 2)}>
- <Worksheet>
- </Worksheet>
- <Worksheet>
- </Worksheet>
- </SpreadSheets>
- </div>
- <div class="sample-panel">
- <div id="panel2"></div>
- </div>
- </div>
复制代码
3. 对每个透视页分别加上自己的透视面板
- initPivotTable(sheet, id) {
- let myPivotTable = sheet.pivotTables.add("myPivotTable", "tableSales", 1, 1, GC.Spread.Pivot.PivotTableLayoutType.outline, GC.Spread.Pivot.PivotTableThemes.light8);
- myPivotTable.suspendLayout();
- if(id) {
- let panel = new GC.Spread.Pivot.PivotPanel("myPivotPanel1", myPivotTable, document.getElementById("panel2"));
- panel.sectionVisibility(GC.Spread.Pivot.PivotPanelSection.fields + GC.Spread.Pivot.PivotPanelSection.area);
- } else {
- let panel = new GC.Spread.Pivot.PivotPanel("myPivotPanel2", myPivotTable, document.getElementById("panel"));
- panel.sectionVisibility(GC.Spread.Pivot.PivotPanelSection.fields + GC.Spread.Pivot.PivotPanelSection.area);
- }
- ...
复制代码
4. 操作:控制第一个透视面板时,数据透视的结果却出现在第二个透视表中,控制错乱。
完整jsx代码:
- import * as React from 'react';
- import * as ReactDOM from 'react-dom';
- import GC from '@grapecity/spread-sheets';
- import "@grapecity/spread-sheets-pivot-addon";
- import '@grapecity/spread-sheets-resources-zh';
- GC.Spread.Common.CultureManager.culture("zh-cn");
- import { SpreadSheets, Worksheet } from '@grapecity/spread-sheets-react';
- import './styles.css';
- const Component = React.Component;
- function _getElementById(id) {
- return document.getElementById(id);
- }
- class App extends Component {
- constructor(props) {
- super(props);
- }
- render() {
- return (
- <div class='wrapper'>
- <div class="sample-tutorial">
- <div class="sample-spreadsheets">
- <SpreadSheets workbookInitialized={spread=>this.initSpread(spread)}>
- <Worksheet>
- </Worksheet>
- <Worksheet>
- </Worksheet>
- </SpreadSheets>
- </div>
- <div class="sample-panel">
- <div id="panel"></div>
- </div>
- </div>
- <div class="sample-tutorial">
- <div class="sample-spreadsheets">
- <SpreadSheets workbookInitialized={spread=>this.initSpread(spread, 2)}>
- <Worksheet>
- </Worksheet>
- <Worksheet>
- </Worksheet>
- </SpreadSheets>
- </div>
- <div class="sample-panel">
- <div id="panel2"></div>
- </div>
- </div>
- </div>
-
- );
- }
- initSpread(spread, id) {
- this.initSheets(spread);
- let pivotLayoutSheet = spread.getSheet(0);
- this.initPivotTable(pivotLayoutSheet, id);
- }
- initPivotTable(sheet, id) {
- let myPivotTable = sheet.pivotTables.add("myPivotTable", "tableSales", 1, 1, GC.Spread.Pivot.PivotTableLayoutType.outline, GC.Spread.Pivot.PivotTableThemes.light8);
- myPivotTable.suspendLayout();
- if(id) {
- let panel = new GC.Spread.Pivot.PivotPanel("myPivotPanel1", myPivotTable, document.getElementById("panel2"));
- panel.sectionVisibility(GC.Spread.Pivot.PivotPanelSection.fields + GC.Spread.Pivot.PivotPanelSection.area);
- } else {
- let panel = new GC.Spread.Pivot.PivotPanel("myPivotPanel2", myPivotTable, document.getElementById("panel"));
- panel.sectionVisibility(GC.Spread.Pivot.PivotPanelSection.fields + GC.Spread.Pivot.PivotPanelSection.area);
- }
- myPivotTable.options.showRowHeader = true;
- myPivotTable.options.showColumnHeader = true;
- myPivotTable.add("salesperson", "Salesperson", GC.Spread.Pivot.PivotTableFieldType.rowField);
- myPivotTable.add("car", "Cars", GC.Spread.Pivot.PivotTableFieldType.rowField);
- myPivotTable.add("date", "Date", GC.Spread.Pivot.PivotTableFieldType.columnField);
- let groupInfo = { originFieldName: "date", dateGroups: [{ by: GC.Pivot.DateGroupType.quarters }] };
- myPivotTable.group(groupInfo);
- myPivotTable.add("total", "Totals", GC.Spread.Pivot.PivotTableFieldType.valueField, GC.Pivot.SubtotalType.sum);
- myPivotTable.resumeLayout();
- myPivotTable.autoFitColumn();
- }
- initSheets (spread) {
- spread.suspendPaint();
- let sheet = spread.getSheet(1);
- sheet.name("DataSource");
- sheet.setRowCount(117);
- sheet.setColumnWidth(0, 120);
- sheet.getCell(-1, 0).formatter("YYYY-mm-DD");
- sheet.getRange(-1,4,0,2).formatter("$ #,##0");
- sheet.setArray(0, 0, pivotSales);
- let table = sheet.tables.add('tableSales', 0, 0, 117, 6);
- for(let i=2;i<=117;i++)
- {
- sheet.setFormula(i-1,5,'=D'+i+'*E'+i)
- }
- table.style(GC.Spread.Sheets.Tables.TableThemes["none"]);
- let sheet0 = spread.getSheet(0);
- sheet0.name("PivotLayout");
- spread.resumePaint();
- }
- }
- ReactDOM.render(<App />, _getElementById('app'));
复制代码 完整css代码
- .wrapper {
- height: 100%;
-
- }
- .sample-tutorial {
- position: relative;
- height: 48%;
- margin-bottom: 20px;
- }
- .sample-spreadsheets {
- width: calc(100% - 300px);
- height: 100%;
- overflow: hidden;
- float: left;
- }
- body {
- position: absolute;
- top: 0;
- bottom: 0;
- left: 0;
- right: 0;
- overflow: hidden;
- }
- .sample-panel {
- float: right;
- width: 300px;
- padding: 12px;
- height: 100%;
- box-sizing: border-box;
- background: #fbfbfb;
- overflow: auto;
- }
- .gc-panel {
- padding: 10px;
- background-color: rgb(230, 230, 230);
- }
- #panel {
- position: absolute;
- right: 0;
- width: 300px;
- height: 100%;
- top: 0;
- }
- #panel2 {
- position: absolute;
- right: 0;
- width: 300px;
- height: 100%;
- bottom: 0;
- }
- #app {
- height: 100%;
- }
复制代码
|
|