A TableSheet has an interactive TableSheet Panel.
Create a TableSheet Panel:
The constructor of the TableSheet Panel has 4 parameters:
Parameter
Type
Description
name
string
The table sheet panel name.
tableSheet
GC.Spread.Sheets.TableSheet.TableSheet
The table sheet.
host
HTMLElement
The host element.
options
Object
The initialization options.
options.showSource
GC.Spread.Sheets.TableSheet.ShowSourceOptions
How to show a column value.
The enum GC.Spread.Sheets.TableSheet.ShowSourceOptions has 4 options.
Key
Value
Description
none
0
Doesn't show a column value.
field
1
Shows a column value when it is own field or related field.
formula
2
Shows a column value when it is calculated field.
all
3
Shows a column value, no matter it is own field, related field, or calculated field.
Attaching a TableSheet Panel to a TableSheet:
Detaching the TableSheet Panel from the TableSheet:
Destroying the TableSheet Panel:
Find a TableSheet Panel by its host element:
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 GC from '@mescius/spread-sheets';
import "@mescius/spread-sheets-tablesheet";
import { SpreadSheets } from '@mescius/spread-sheets-react';
import './styles.css';
export function AppFunc() {
const initSpread = (spread) => {
spread.suspendPaint();
spread.clearSheets();
spread.options.autoFitType = GC.Spread.Sheets.AutoFitType.cellWithHeader;
//init a data manager
var baseApiUrl = getBaseApiUrl();
var dataManager = spread.dataManager();
//add order table
var orderTable = dataManager.addTable("orderTable", {
remote: {
read: {
url: baseApiUrl + "/Order"
}
}
});
//add customer table
var customerTable = dataManager.addTable("customerTable", {
remote: {
read: {
url: baseApiUrl + "/Customer"
}
}
});
//add relationship between order table and customer table
dataManager.addRelationship(orderTable, "CustomerId", "customer", customerTable, "Id", "orders");
//init a table sheet
var sheet = spread.addSheetTab(0, "TableSheet1", GC.Spread.Sheets.SheetType.tableSheet);
sheet.options.allowAddNew = false; //hide new row
//bind a view to the table sheet
var style = { formatter: 'MM/dd/yyyy' };
var view = orderTable.addView("myView", [
{ value: "Id", width: 80 },
{ value: "CustomerId", width: 120 },
{ value: "ShipName", width: 100 },
{ value: "EmployeeId", width: 120 },
{ value: "OrderDate", width: 100, style: style },
{ value: "RequiredDate", width: 120, style: style },
{ value: "ShippedDate", width: 120, style: style },
{ value: "ShipVia", width: 80 },
{ value: "Freight", width: 80 },
{ value: "ShipAddress", width: 120 },
{ value: "ShipCity", width: 100 },
{ value: "ShipRegion", width: 100 },
{ value: "ShipPostalCode", width: 140 },
{ value: "ShipState", width: 120 },
{ value: "customer", width: 120, isRelationship: true, visible: false },
{ value: "customer.Id", width: 120, isRelationship: true, visible: false },
{ value: "customer.CompanyName", width: 120, isRelationship: true, visible: false },
{ value: "customer.ContactName", width: 120, isRelationship: true, visible: false },
{ value: "customer.ContactTitle", width: 120, isRelationship: true, visible: false },
{ value: "customer.Address", width: 120, isRelationship: true, visible: false },
{ value: "customer.City", width: 120, isRelationship: true, visible: false },
{ value: "customer.Region", width: 120, isRelationship: true, visible: false },
{ value: "customer.PostalCode", width: 120, isRelationship: true, visible: false },
{ value: "customer.State", width: 120, isRelationship: true, visible: false },
{ value: "customer.Phone", width: 120, isRelationship: true, visible: false },
]); //the View has all default columns of the Table
view.fetch().then(function () {
sheet.setDataView(view);
//init a table sheet panel
var host = document.getElementById("panel");
var panel = new GC.Spread.Sheets.TableSheet.TableSheetPanel("myPanel", sheet, host);
});
spread.resumePaint();
}
return (
<div class="sample-tutorial">
<div class="sample-spreadsheets">
<SpreadSheets workbookInitialized={spread => initSpread(spread)}>
</SpreadSheets>
</div>
<div id="panel" class="container"></div>
</div>
);
}
function getBaseApiUrl() {
return window.location.href.match(/http.+spreadjs\/demos\//)[0] + 'server/api';
}
/*REPLACE_MARKER*/
/*DO NOT DELETE THESE COMMENTS*/
import * as React from 'react';
import GC from '@mescius/spread-sheets';
import "@mescius/spread-sheets-tablesheet";
import { SpreadSheets } from '@mescius/spread-sheets-react';
import './styles.css';
const Component = React.Component;
export class App extends Component {
render() {
return (
<div class="sample-tutorial">
<div class="sample-spreadsheets">
<SpreadSheets workbookInitialized={spread => this.initSpread(spread)}>
</SpreadSheets>
</div>
<div id="panel" class="container"></div>
</div>
);
}
initSpread(spread) {
spread.suspendPaint();
spread.clearSheets();
spread.options.autoFitType = GC.Spread.Sheets.AutoFitType.cellWithHeader;
//init a data manager
var baseApiUrl = getBaseApiUrl();
var dataManager = spread.dataManager();
//add order table
var orderTable = dataManager.addTable("orderTable", {
remote: {
read: {
url: baseApiUrl + "/Order"
}
}
});
//add customer table
var customerTable = dataManager.addTable("customerTable", {
remote: {
read: {
url: baseApiUrl + "/Customer"
}
}
});
//add relationship between order table and customer table
dataManager.addRelationship(orderTable, "CustomerId", "customer", customerTable, "Id", "orders");
//init a table sheet
var sheet = spread.addSheetTab(0, "TableSheet1", GC.Spread.Sheets.SheetType.tableSheet);
sheet.options.allowAddNew = false; //hide new row
//bind a view to the table sheet
var style = { formatter: 'MM/dd/yyyy' };
var view = orderTable.addView("myView", [
{ value: "Id", width: 80 },
{ value: "CustomerId", width: 120 },
{ value: "ShipName", width: 100 },
{ value: "EmployeeId", width: 120 },
{ value: "OrderDate", width: 100, style: style },
{ value: "RequiredDate", width: 120, style: style },
{ value: "ShippedDate", width: 120, style: style },
{ value: "ShipVia", width: 80 },
{ value: "Freight", width: 80 },
{ value: "ShipAddress", width: 120 },
{ value: "ShipCity", width: 100 },
{ value: "ShipRegion", width: 100 },
{ value: "ShipPostalCode", width: 140 },
{ value: "ShipState", width: 120 },
{ value: "customer", width: 120, isRelationship: true, visible: false },
{ value: "customer.Id", width: 120, isRelationship: true, visible: false },
{ value: "customer.CompanyName", width: 120, isRelationship: true, visible: false },
{ value: "customer.ContactName", width: 120, isRelationship: true, visible: false },
{ value: "customer.ContactTitle", width: 120, isRelationship: true, visible: false },
{ value: "customer.Address", width: 120, isRelationship: true, visible: false },
{ value: "customer.City", width: 120, isRelationship: true, visible: false },
{ value: "customer.Region", width: 120, isRelationship: true, visible: false },
{ value: "customer.PostalCode", width: 120, isRelationship: true, visible: false },
{ value: "customer.State", width: 120, isRelationship: true, visible: false },
{ value: "customer.Phone", width: 120, isRelationship: true, visible: false },
]); //the View has all default columns of the Table
view.fetch().then(function () {
sheet.setDataView(view);
//init a table sheet panel
var host = document.getElementById("panel");
var panel = new GC.Spread.Sheets.TableSheet.TableSheetPanel("myPanel", sheet, host);
});
spread.resumePaint();
}
}
function getBaseApiUrl() {
return window.location.href.match(/http.+spreadjs\/demos\//)[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$/en/react/node_modules/@mescius/spread-sheets/styles/gc.spread.sheets.excel2013white.css">
<!-- SystemJS -->
<script src="$DEMOROOT$/en/react/node_modules/systemjs/dist/system.src.js"></script>
<script src="systemjs.config.js"></script>
<script>
System.import('$DEMOROOT$/en/lib/react/license.js').then(function () {
System.import('./src/app');
});
</script>
</head>
<body>
<div id="app" style="height: 100%;"></div>
</body>
</html>
.sample-tutorial {
position: relative;
height: 100%;
overflow: hidden;
}
.sample-spreadsheets {
width: calc(100% - 303px);
height: 100%;
overflow: hidden;
float: left;
}
body {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
margin: 0;
}
.container {
width: 300px;
height: 100%;
float: left;
border: 1px solid lightgrey;
}
(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: {
'@mescius/spread-sheets': 'npm:@mescius/spread-sheets/index.js',
'@mescius/spread-sheets-tablesheet': 'npm:@mescius/spread-sheets-tablesheet/index.js',
'@mescius/spread-sheets-react': 'npm:@mescius/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);