您好,我这边加了一个按钮,在修改完毕后点击按钮输出信息到控制台就可以看见更改的数据了:
代码如下:
- import "./App.css";
- import React, { useState, useRef } from "react";
- import * as GC from "@grapecity/spread-sheets";
- import { SpreadSheets, Worksheet } from "@grapecity/spread-sheets-react";
- import "@grapecity/spread-sheets-tablesheet";
- import "@grapecity/spread-sheets-ganttsheet";
- import "../node_modules/@grapecity/spread-sheets/styles/gc.spread.sheets.excel2013white.css";
- import "@grapecity/spread-sheets-resources-zh";
- GC.Spread.Common.CultureManager.culture("zh-cn");
- function App() {
- // state
- const [spreadVal, setSpreadVal] = useState<any>(null);
- // init
- let initSpread = function (value: any) {
- let spread = value;
- setSpreadVal(spread);
- initGanttSheetWithChildrenData(spread);
- };
- // function getBaseApiUrl() {
- // return "https://developer.mescius.com/spreadjs/demos/server/api"
- // }
- function initGanttSheetWithChildrenData(spread: any) {
- // var tableName = "Gantt_Children";
- // var baseApiUrl = getBaseApiUrl();
- // var apiUrl = baseApiUrl + "/" + tableName;
- var dataManager = spread.dataManager();
- var myTable1 = dataManager?.addTable("myTable1", {
- batch: true,
- // remote: {
- // read: {
- // url: apiUrl
- // }
- // },
- data: [
- {
- id: 1,
- parentId: null,
- taskNumber: 1,
- name: "Plan for Project Server 2013 deployment",
- duration: "1 day",
- predecessors: "",
- level: 1,
- resource: 1,
- cost: 100,
- },
- ],
- schema: {
- hierarchy: {
- type: "ChildrenPath",
- column: "children",
- },
- },
- });
- var ganttSheet = spread.addSheetTab(
- 2,
- "GanttSheet3",
- GC.Spread.Sheets.SheetType.ganttSheet
- );
- var view = myTable1?.addView("myView1", [
- { value: "taskNumber", caption: "NO.", width: 60 },
- { value: "name", caption: "Task Name", width: 200 },
- { value: "duration", caption: "Duration", width: 90 },
- { value: "predecessors", caption: "Predecessors", width: 120 },
- ]);
- view?.fetch().then(function () {
- ganttSheet.bindGanttView(view);
- });
- }
- function click() {
- let spread = spreadVal;
- console.log(spread.dataManager().tables.myTable1.getChanges(), "<<<<");
- }
- return (
- <div className="sample-tutorial">
- <div className="sample-spreadsheets">
- <SpreadSheets
- workbookInitialized={(spread) => initSpread(spread)}
- ></SpreadSheets>
- <button onClick={click}>Click</button>
- </div>
- </div>
- );
- }
- export default App;
复制代码 |