Overview

Tables make it easier to manage and analyze related spreadsheet data. Like Excel, SpreadJS provides support for tables with support for AutoExpand, conditional formatting, data validation, a built-in context menu, fixed scrolling headers, table resize and navigation, total summary row, and more.

Description
app.js
index.html
styles.css
Copy to CodeMine

You can add a table in two different ways. The first way is to add an empty table by using the add method, as shown in the following code:

    var spread = GC.Spread.Sheets.findControl(document.getElementById('ss'));
    var sheet = spread.getActiveSheet();
    var tableStyle = GC.Spread.Sheets.Tables.TableThemes.light1;
    var table = sheet.tables.add('table1', 0, 0, 4, 4, tableStyle);
    // set value to the table
    sheet.setArray(0, 0, [
       ['Id', 'Name', 'Age', 'Grade'],
       [1000, 'Tom', 23, 98],
       [1001, 'Bob', 22, 80],
       [1002, 'Tony', 23, 99]
    ]);

The second way is add a table by data source using the addFromDataSource method. For example:

    var source = [
    { LastName: 'Jone', FirstName: 'Nancy',Phone: '(123)555-0100'},
    { LastName: 'Tom', FirstName: 'Andrew',Phone: '(123)555-0100'},
    { LastName: 'Kotas', FirstName: 'Jan', Phone: '(123)555-0100'} ]
    var table = sheet.tables.addFromDataSource('table2', 1, 1, source);

Using the second way lets you initialize data for the table.

You can add a table in two different ways. The first way is to add an empty table by using the add method, as shown in the following code: The second way is add a table by data source using the addFromDataSource method. For example: Using the second way lets you initialize data for the table.
window.onload = function () { var spread = new GC.Spread.Sheets.Workbook(document.getElementById("ss")); initSpread(spread); }; function initSpread(spread) { var spreadNS = GC.Spread.Sheets; var sheet = spread.getSheet(0); var source = [ { Course: "Calculus", Term: 1, Credit: 5, Score: 80, Teacher: "Nancy Feehafer" }, { Course: "P.E.", Term: 1, Credit: 3.5, Score: 85, Teacher: "Andrew Cencini" }, { Course: "Political Economics", Term: 1, Credit: 3.5, Score: 95, Teacher: "Jan Kotas" }, { Course: "Basic of Computer", Term: 1, Credit: 2, Score: 85, Teacher: "Steven Thorpe" }, { Course: "Micro-Economics", Term: 1, Credit: 4, Score: 62, Teacher: "Jan Kotas" }, { Course: "Linear Algebra", Term: 2, Credit: 5, Score: 73, Teacher: "Nancy Feehafer" }, { Course: "Accounting", Term: 2, Credit: 3.5, Score: 86, Teacher: "Nancy Feehafer" }, { Course: "Statistics", Term: 2, Credit: 5, Score: 85, Teacher: "Robert Zare" }, { Course: "Marketing", Term: 2, Credit: 4, Score: 70, Teacher: "Laura Giussani" } ]; spread.suspendPaint(); var table = sheet.tables.addFromDataSource("Table1", 2, 1, source, spreadNS.Tables.TableThemes.medium7); table.showFooter(true); table.showHeader(true); table.highlightFirstColumn(true); table.highlightLastColumn(false); table.setColumnFormula(2, "=SUBTOTAL(109,[Credit])"); table.setColumnFormula(3, "=SUBTOTAL(109,[Score])"); table.setColumnValue(0, "Total"); sheet.setColumnWidth(0, 20); sheet.setColumnWidth(1, 130); sheet.setColumnWidth(2, 70); sheet.setColumnWidth(3, 70); sheet.setColumnWidth(4, 70); sheet.setColumnWidth(5, 100); spread.resumePaint(); }
<!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/purejs/node_modules/@mescius/spread-sheets/styles/gc.spread.sheets.excel2013white.css"> <script src="$DEMOROOT$/en/purejs/node_modules/@mescius/spread-sheets/dist/gc.spread.sheets.all.min.js" type="text/javascript"></script> <script src="$DEMOROOT$/spread/source/js/license.js" type="text/javascript"></script> <script src="app.js" type="text/javascript"></script> <link rel="stylesheet" type="text/css" href="styles.css"> </head> <body> <div class="sample-tutorial"> <div id="ss" style="width:100%; height: 100%"></div> </div> </body> </html>
.sample-tutorial { position: relative; height: 100%; overflow: hidden; } body { position: absolute; top: 0; bottom: 0; left: 0; right: 0; }