SpreadJS的TableSheet允许用户通过以下选项切换行号标题的可见性:
显示行号标题:
隐藏行号标题:
import * as React from 'react';
import { createRoot } from 'react-dom/client';
import './styles.css';
import { AppFunc } from './app-func';
// import { App } from './app-class';
// 1. Functional Component sample
createRoot(document.getElementById('app')).render(<AppFunc />);
// 2. Class Component sample
// createRoot(document.getElementById('app')).render(<App />);
/*REPLACE_MARKER*/
/*DO NOT DELETE THESE COMMENTS*/
import * as React from 'react';
import { useState } from 'react'
import { createRoot } from 'react-dom/client';
import GC from '@grapecity-software/spread-sheets';
import "@grapecity-software/spread-sheets-tablesheet";
import '@grapecity-software/spread-sheets-resources-zh';
GC.Spread.Common.CultureManager.culture("zh-cn");
import { SpreadSheets, Worksheet } from '@grapecity-software/spread-sheets-react';
import './styles.css';
export function AppFunc() {
const [spread, setSpread] = useState(null);
const [tablesheet, setTablesheet] = useState(null);
const [rowNumberVisible, toggleRowNumberVisible] = useState(true);
let initSpread = function (value) {
setSpread(value);
value.suspendPaint();
value.clearSheets();
value.options.autoFitType = GC.Spread.Sheets.AutoFitType.cellWithHeader;
//init a data manager
var dataManager = value.dataManager();
var productTable = dataManager.addTable("productTable", {
remote: {
read: {
url: getBaseApiUrl() + "/Product"
}
}
});
//init a table sheet
var sheet = value.addSheetTab(0, "MyTableSheet", GC.Spread.Sheets.SheetType.tableSheet);
//bind a view to the table sheet
productTable.fetch().then(function () {
var myView = productTable.addView("myView", [
{ value: "ProductName", caption: "Name", width: 250 },
{ value: "QuantityPerUnit", caption: "Quantity Per Unit", width: 140 },
{ value: "UnitPrice", caption: "Unit Price", width: 140 },
{ value: "UnitsInStock", caption: "Units In Stock", width: 140 },
{ value: "UnitsOnOrder", caption: "Units On Order", width: 140 },
{ value: "Discontinued", width: 120 }
]);
sheet.setDataView(myView);
sheet.options.showRowNumber = true;
});
setTablesheet(sheet);
value.resumePaint();
}
let toggleRowNumber = function (checked) {
toggleRowNumberVisible(checked);
tablesheet.options.showRowNumber = checked;
}
return (
<div class="sample-tutorial">
<div class="sample-spreadsheets">
<SpreadSheets workbookInitialized={spread => {
initSpread(spread);
}}></SpreadSheets>
</div>
<div id="options-container" class="options-container">
<fieldset>
<legend>Row Number</legend>
<div class="field-line">
<span>visible: </span><input type="checkbox" onChange={(e) => { toggleRowNumber(e.target.checked) }} checked={rowNumberVisible} id="show-button" />
</div>
</fieldset>
</div>
</div>
);
}
function getBaseApiUrl() {
return window.location.href.match(/http.+spreadjs\/SpreadJSTutorial\//)[0] + 'server/api';
}
/*REPLACE_MARKER*/
/*DO NOT DELETE THESE COMMENTS*/
import * as React from 'react';
import { createRoot } from 'react-dom/client';
import GC from '@grapecity-software/spread-sheets';
import "@grapecity-software/spread-sheets-tablesheet";
import '@grapecity-software/spread-sheets-resources-zh';
GC.Spread.Common.CultureManager.culture("zh-cn");
import { SpreadSheets, Worksheet } from '@grapecity-software/spread-sheets-react';
import './styles.css';
const Component = React.Component;
export class App extends Component {
constructor(props) {
super(props);
this.spread = null;
this.tablesheet = null;
this.state = {
rowNumberVisible: true
};
}
render() {
const {
rowNumberVisible
} = this.state;
return (
<div class="sample-tutorial">
<div class="sample-spreadsheets">
<SpreadSheets workbookInitialized={spread => {
this.initSpread(spread);
}}></SpreadSheets>
</div>
<div id="options-container" class="options-container">
<fieldset>
<legend>Row Number</legend>
<div class="field-line">
<span>visible: </span><input type="checkbox" onChange={(e) => { this.setState({ rowNumberVisible: e.target.checked }, () => { this.toggleRowNumber() }); }} checked={rowNumberVisible} id="show-button" />
</div>
</fieldset>
</div>
</div>
);
}
initSpread(spread) {
this.spread = spread;
spread.suspendPaint();
spread.clearSheets();
spread.options.autoFitType = GC.Spread.Sheets.AutoFitType.cellWithHeader;
//init a data manager
var dataManager = spread.dataManager();
var productTable = dataManager.addTable("productTable", {
remote: {
read: {
url: getBaseApiUrl() + "/Product"
}
}
});
//init a table sheet
var sheet = this.tablesheet = spread.addSheetTab(0, "MyTableSheet", GC.Spread.Sheets.SheetType.tableSheet);
//bind a view to the table sheet
productTable.fetch().then(function () {
var myView = productTable.addView("myView", [
{ value: "ProductName", caption: "Name", width: 250 },
{ value: "QuantityPerUnit", caption: "Quantity Per Unit", width: 140 },
{ value: "UnitPrice", caption: "Unit Price", width: 140 },
{ value: "UnitsInStock", caption: "Units In Stock", width: 140 },
{ value: "UnitsOnOrder", caption: "Units On Order", width: 140 },
{ value: "Discontinued", width: 120 }
]);
sheet.setDataView(myView);
sheet.options.showRowNumber = true;
});
spread.resumePaint();
}
toggleRowNumber() {
this.tablesheet.options.showRowNumber = this.state.rowNumberVisible;
}
}
function getBaseApiUrl() {
return window.location.href.match(/http.+spreadjs\/SpreadJSTutorial\//)[0] + 'server/api';
}
<!doctype html>
<html style="height:100%;font-size:14px;">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" type="text/css" href="$DEMOROOT$/zh/react/node_modules/@grapecity-software/spread-sheets/styles/gc.spread.sheets.excel2013white.css">
<!-- SystemJS -->
<script src="$DEMOROOT$/zh/react/node_modules/systemjs/dist/system.src.js"></script>
<script src="$DEMOROOT$/spread/source/data/employees.js" type="text/javascript"></script>
<script src="systemjs.config.js"></script>
<script>
System.import('$DEMOROOT$/zh/lib/react/license.js').then(function () {
System.import('./src/app');
});
</script>
</head>
<body>
<div id="app" style="height: 100%;"></div>
</body>
</html>
body {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
}
fieldset {
padding: 6px;
margin: 0;
margin-top: 10px;
}
.sample-tutorial {
position: relative;
height: 100%;
overflow: hidden;
}
.sample-spreadsheets {
width: calc(100% - 280px);
height: 100%;
overflow: hidden;
float: left;
}
.options-container {
float: right;
width: 280px;
padding: 12px;
height: 100%;
box-sizing: border-box;
background: #fbfbfb;
overflow: auto;
}
fieldset span,
fieldset input,
fieldset select {
display: inline-block;
text-align: left;
}
fieldset input[type=text] {
width: calc(100% - 58px);
}
fieldset input[type=button] {
width: 100%;
text-align: center;
}
fieldset select {
width: calc(100% - 50px);
}
.field-line {
margin-top: 4px;
}
.field-inline {
display: inline-block;
vertical-align: middle;
}
fieldset label.field-inline {
width: 100px;
}
fieldset input.field-inline {
width: calc(100% - 100px - 12px);
}
.required {
color: red;
font-weight: bold;
}
#fields {
display: none;
}
#fields.show {
display: block;
}
(function (global) {
System.config({
transpiler: 'plugin-babel',
babelOptions: {
es2015: true,
react: true
},
meta: {
'*.css': { loader: 'css' }
},
paths: {
// paths serve as alias
'npm:': 'node_modules/'
},
// map tells the System loader where to look for things
map: {
'@grapecity-software/spread-sheets': 'npm:@grapecity-software/spread-sheets/index.js',
'@grapecity-software/spread-sheets-resources-zh': 'npm:@grapecity-software/spread-sheets-resources-zh/index.js',
'@grapecity-software/spread-sheets-tablesheet': 'npm:@grapecity-software/spread-sheets-tablesheet/index.js',
'@grapecity-software/spread-sheets-react': 'npm:@grapecity-software/spread-sheets-react/index.js',
'@grapecity/jsob-test-dependency-package/react-components': 'npm:@grapecity/jsob-test-dependency-package/react-components/index.js',
'react': 'npm:react/cjs/react.production.js',
'react-dom': 'npm:react-dom/cjs/react-dom.production.js',
'react-dom/client': 'npm:react-dom/cjs/react-dom-client.production.js',
'scheduler': 'npm:scheduler/cjs/scheduler.production.js',
'css': 'npm:systemjs-plugin-css/css.js',
'plugin-babel': 'npm:systemjs-plugin-babel/plugin-babel.js',
'systemjs-babel-build':'npm:systemjs-plugin-babel/systemjs-babel-browser.js'
},
// packages tells the System loader how to load when no filename and/or no extension
packages: {
src: {
defaultExtension: 'jsx'
},
"node_modules": {
defaultExtension: 'js'
},
}
});
})(this);