Skip to content

Tables

You'll find below all the available methods to interact with the tables of a SeaTable base.

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.

You can have a look at the specific view, column or row structure on the corresponding pages.

Get Table(s)

getActiveTable

Get the currently selected table.

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();
output.text(tables);

getTableByName

Get a table object by its name.

base.getTableByName(tableName: String);

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

Example

const table = base.getTableByName('Table1');
// Display only table _id
output.text(`The id of the table is: ${table._id}`);
// Display whole table structure
output.text(table);

Add Table

addTable

Add a new table to this base, given the new table name tableName. Please ensure that you choose a tableName that doesn't already exists in your base.

base.addTable(tableName: String);
Output Nothing

Example

base.addTable('New table');
output.text("Wow, I just added a new table to this base.")

Rename Table

renameTable

Rename an existing table named oldName to newName. Please ensure that you choose a newName that doesn't already exists in your base.

base.renameTable(oldName: String, newName: String);

Output Nothing (throws an error if no table named oldName exists)

Example

const old_name = "Table1";
const new_name = "Projects 2023";
base.renameTable(old_name, new_name);
output.text(`This base ${old_name} got a new name: ${new_name}`);

Delete Table

deleteTable

Delete a table named tableName from the base. By the way, the table can be restored from the logs. Deleting the last table is not possible.

base.deleteTable(tableName: String);
Output Nothing (throws an error if no table named tableName exists)

Example

base.deleteTable('Old table');