Skip to content

Tables

Global structure

Here is the global structure of a table object:

{
    "_id": "IfcB",
    "name": "New table",
    "is_header_locked": false,
    "summary_configs": {},
    "columns": [ // (1)!
        {
        "key": "0000",
        "type": "number",
        "name": "First column",
        "editable": true,
        "width": 200,
        "resizable": true,
        "draggable": true,
        "data": null,
        "permission_type": "",
        "permitted_users": []
        },
        {
        "key": "2w6F",
        "type": "text",
        "name": "second column",
        "editable": true,
        "width": 200,
        "resizable": true,
        "draggable": true,
        "data": null,
        "permission_type": "",
        "permitted_users": []
        },
        {
        "key": "3aAf",
        "type": "date",
        "name": "third column",
        "editable": true,
        "width": 200,
        "resizable": true,
        "draggable": true,
        "data": null,
        "permission_type": "",
        "permitted_users": []
        }
    ],
    "rows": [], // (2)!
    "views": [ // (3)!
        {
        "_id": "0000",
        "name": "Default View",
        "type": "table",
        "is_locked": false,
        "filter_conjunction": "And",
        "filters": [],
        "sorts": [],
        "groupbys": [],
        "group_rows": [],
        "groups": [],
        "colorbys": {},
        "hidden_columns": [],
        "rows": [],
        "formula_rows": {},
        "link_rows": {},
        "summaries": {},
        "colors": {}
        }
    ],
    "id_row_map": {}
}

  1. Array of existing columns

    {
      "key": "g4s1",
      "type": "number",
      "name": "api3",
      "editable": true,
      "width": 200,
      "resizable": true,
      "draggable": true,
      "data": null,
      "permission_type": "",
      "permitted_users": []
    }
    

  2. Array of existing rows

    {
    "_id": "Qtf7xPmoRaiFyQPO1aENTjb",
    "_mtime": "2021-03-10T16:19:31.761+00:00",
    "Name": "NewName",
    "Date": "2020-08-01",
    "Content": "111",
    "link": [
                {
                "display_value": "1",
                "row_id": "XzdZfL2oS-aILnhfagTWEg"
                }
            ]
    }
    

  3. Array of existing views

    {
      "_id": "0000",
      "name": "Default View",
      "type": "table",
      "is_locked": false,
      "rows": [],
      "formula_rows": {},
      "summaries": [],
      "filter_conjunction": "And",
      "sorts": [],
      "filters": [],
      "hidden_columns": [],
      "groupbys": [],
      "group_rows": [],
      "groups": []
    }
    
    Please refer to the SeaTable API Reference for a more detailed presentation.

Get Table(s)

getActiveTable

Get the currently selected table. Only available in SeaTable scripts.

base.getActiveTable();
Output Single table object

Example

const table = base.getActiveTable();
output.text(`The name of the active table is: ${table.name}`);

getTables

Get all tables of the current base.

base.getTables();
Output Array of table objects

Example

const tables = base.getTables();

getTableByName

Get a table object by its name.

base.getTableByName(tableName);

Output Single table object (undefined if table doesn't exist)

Example

const table = base.getTableByName('Table1');

Add Table

addTable

Add a new table to this base. Ensure the name doesn't already exist.

base.addTable(tableName, lang='en', columns=[]);

The lang and columns parameters are optional.

Example

base.addTable('New table');

Rename Table

renameTable

Rename an existing table.

base.renameTable(oldName, newName);

Example

base.renameTable('Table1', 'Projects 2023');

Delete Table

deleteTable

Delete a table from the base. The table can be restored from the logs. Deleting the last table is not possible.

base.deleteTable(tableName);

Example

base.deleteTable('Old table');