Skip to content

Views

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

Global structure

Here is the global structure of a view object:

{
    "_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 View(s)

getActiveView

Get the current view of the active table.

base.getActiveView();

Output Single view object

Example

const view  = base.getActiveView();
output.text(view._id);
output.text(view);

getViewByName

Get a view of a particular table, specified by its name viewName.

base.getViewByName(table: Object/String/* (1)! */, viewName: String);
  1. table: either a table object or the table name

Output Single view object (undefined if no view called viewName exists, throws an error if table doesn't exist)

Example

const table  = base.getTableByName('Table1');
const view = base.getViewByName(table, 'Default View');
output.text(view.name);

const view = base.getViewByName('Table1', 'Default View');
output.text(view.name);

listViews / getViews (deprecated)

Get all the views of the table.

base.listViews(table: Object/String/* (1)! */);
  1. table: either a table object or the table name

Output Array of view objects (throws an error if table doesn't exist)

Example

const table  = base.getTableByName('Table1');
const views = base.listViews(table);
output.text(views.length);

Add View

addView

Add a view named viewName to a table.

base.addView(table: Object/String/* (1)! */, viewName: String);
  1. table: either a table object or the table name

Output Nothing (throws an error if table doesn't exist)

Example

const table  = base.getTableByName('Table1');
base.addView(table, 'view 2');

base.addView('Table1', 'view 2');

Rename View

renameView

Rename a view in the table specified by its current name currentViewName and its new name nextViewName. Please ensure that you choose a nextViewName that doesn't already exists in your table.

base.renameView(table: Object/String/* (1)! */, currentViewName: String, nextViewName: String);
  1. table: either a table object or the table name

Output Nothing (throws an error if table or currentViewName doesn't exist)

Example

const table  = base.getTableByName('Table1');
base.renameView(table, 'Default View', 'view2');

base.renameView('Table1', 'Default View', 'view2');

Delete View

deleteView

Delete a view in a particular table, specified by its name viewName. Deleting the last view is not possible.

base.deleteView(table: Object/String/* (1)! */, viewName: String);
  1. table: either a table object or the table name

Output Nothing (throws an error if table doesn't exist or no view called viewName exists)

Example

const table  = base.getTableByName('Table1');
base.deleteView(table, 'view2');

base.deleteView('Table1', 'view2');