Columns¶
You'll find below all the available methods to interact with the columns of a SeaTable table.
Global structure¶
Here is the global structure of a column object:
{
"key":"bjcM",
"type":"number",
"name":"Val",
"editable":true,
"width":200,
"resizable":true,
"draggable":true,
"data": // (1)!
{
"format":"number",
"precision":2,
"enable_precision":false,
"enable_fill_default_value":false,
"enable_check_format":false,
"decimal":"comma",
"thousands":"no",
"format_min_value":0,
"format_max_value":1000
},
"permission_type":"",
"permitted_users":[],
"permitted_group":[],
"edit_metadata_permission_type":"",
"edit_metadata_permitted_users":[],
"edit_metadata_permitted_group":[],
"description":null,
"colorbys":{},
"editor":
{
"key":null,
"ref":null,
"props":{},
"_owner":null
},
"formatter":
{
"key":null,
"ref":null,
"props":{},
"_owner":null
}
}
- See below for a presentation of
dataobject keys depending on the columntype
Columns particularities
- Unless other elements, columns don't have an
_id, but akey - Link-type columns also have a link id that should not be mistaken with the column
key. This value is present in thedataobject (see below)
Column data¶
The data object keys will depend on the column type and will allow you to define the specific column parameters. Here is a list of the different data keys depending on the column type:
text, email, long-text, image, file, url, creator, ctime, last-modifier, mtime
empty
link
number
single select, multiple select
{
"options":
[
{
"name":"Male",
"id":"783482",
"color":"#46A1FD",
"textColor":"#FFFFFF",
"borderColor":"#3C8FE4"
},
{
"name":"Female",
"id":"330935",
"color":"#DC82D2",
"textColor":"#FFFFFF",
"borderColor":"#D166C5"
},
{
"name":"Non-binary",
"id":"147140",
"color":"#ADDF84",
"textColor":"#FFFFFF",
"borderColor":"#9CCF72"
}
],
"cascade_column_key":"Qvkt",
"cascade_settings":
{
"147140":["783482"],
"330935":["330935"],
"783482":["783482"]
}
}
rate
formula
link-formula
{
"formula":"findmax",
"result_type":"array",
"operated_columns":["TaXD"],
"conditions":[],
"link_column_key":"TaXD",
"include_condition":false,
"condition_conjunction":"And",
"column_key_in_linked_record":"0000",
"column_key_for_comparison":"RSjx",
"level2_linked_table_column_key":null,
"array_type":"auto-number",
"array_data":null
}
auto-number
button
Accessing a particular data object value
This rather long list is not exhaustive, however. If you need to access a specific data value, consult the SeaTable API Reference or create the corresponding column to display the content of its data object.
ColumnTypes constants¶
ColumnTypes
When you want to insert/add a column or change a column type, you will need to use these ColumnTypes.
from seatable_api.constants import ColumnTypes # (1)!
ColumnTypes.NUMBER # number
ColumnTypes.TEXT # text
ColumnTypes.LONG_TEXT # long text
ColumnTypes.CHECKBOX # checkbox
ColumnTypes.DATE # date & time
ColumnTypes.SINGLE_SELECT # single select
ColumnTypes.MULTIPLE_SELECT # multiple select
ColumnTypes.IMAGE # image
ColumnTypes.FILE # file
ColumnTypes.COLLABORATOR # collaborator
ColumnTypes.LINK # link to other records
ColumnTypes.FORMULA # formula
ColumnTypes.CREATOR # creator
ColumnTypes.CTIME # create time
ColumnTypes.LAST_MODIFIER # last modifier
ColumnTypes.MTIME # modify time
ColumnTypes.GEOLOCATION # geolocation
ColumnTypes.AUTO_NUMBER # auto munber
ColumnTypes.URL # URL
- Don't forget this particular import to use
ColumnTypes!
Get Column(s)¶
get_column_by_name
Get the column of the table table_name, given the column name column_name.
Output Single column dict (None if no column named column_name exists, throws an error if no table named table_name exists)
Example
list_columns
Get the columns of a table (specified by its name table_name), optionally from a specific view (specified by its name view_name).
Output List of column dicts (throws an error if no table named table_name exists or if no view named view_name exists)
Example
get_columns_by_type
Get all the columns of a specific column_type in the table table_name. See the ColumnTypes constants above or the API Reference for more information about supported column types.
Output List of column dicts (eventually empty; throws an error if no table named table_name exists or if column_type is not a valid ColumnTypes member)
Example
Insert column¶
insert_column
Insert (inside the table) or append (at the end of the table) a column named column_name to the table table_name.
-
column_type: See the ColumnTypes constants above or the API Reference for more information about supported column typescolumn_key(optional): argument specifying the key of the anchor column for the insertion (the newly created column will appear just to the right of the anchor column)column_data(optional): For some particularColumnTypes, specific column data may be provided in thecolumn_datadict. See the column data above for more information.
Output Single column dict (throws an error if no table named table_name exists, if a column named column_name already exists or if column_type is not a valid ColumnTypes member)
Example
Rename column¶
rename_column
Rename the column in the table table_name whose key is column_key with the new name new_column_name. Please ensure that you choose a new_column_name that doesn't already exists in your table table_name.
Output Single column dict (throws an error if no table named table_name exists or if no column with the key column_key exists)
Example
from seatable_api import Base, context
base = Base(context.api_token, context.server_url)
base.auth()
base.rename_column('Table1', '0000', 'new column name') # (1)!
0000is always the key of the first column in each table
from seatable_api import Base, context
base = Base(context.api_token, context.server_url)
base.auth()
column_to_rename = base.get_column_by_name('Table1', 'My Column')
base.rename_column('Table1', column_to_rename['key'], 'new column name') # (1)!
- Accessing the
keyvalue of a column you just retrieved (for example withbase.get_column_by_name), you don't have to explicitly know itscolumn_key
(Un)freeze column¶
(Un)freeze_column
Freeze (fix) or unfreeze the column of table table_name whose key is column_key.
(Un)freezing a group of columns
Please note that this method acts on a single column: to freeze the n-first left columns, please run it for each column!
-
column_key: the key of the column you want to (un)freezefrozen:Trueto freeze,Falseto unfreeze
Output Single column dict (throws an error if no table named table_name exists or if no column with the key column_key exists)
Example
Move column¶
move_column
Move the column of table table_name whose key is column_key.
-
column_key: the key of the column you want to movetarget_column_key: the key of the anchor column for the move (the column whose key iscolumn_keywill be moved just to the right of the anchor column)
Output Single column dict (throws an error if no table named table_name exists or if no column with the key column_key or target_column_key exists)
Example
from seatable_api import Base, context
base = Base(context.api_token, context.server_url)
base.auth()
base.move_column('Table1', 'loPx', '0000') # (1)!
- In this example, the column with the key
loPxwill be moved to the right of the column0000
Modify column type¶
modify_column_type
Change the column type of an existing column of table table_name whose key is column_key.
Don't change column type to ColumnTypes.LINK
This method doesn't allow to pass column data for the moment. Trying to change the column type to ColumnTypes.LINK will then lead to a "broken" column (you won't be able to edit the column's settings) as column data is mandatory for link-type columns.
-
column_key(optional): the key of the column you want to modify the typenew_column_type: See the ColumnTypes constants above or the API Reference for more information about supported column types
Output Single column dict (throws an error if no table named table_name exists, if no column with the key column_key exists or if new_column_type is not a valid ColumnTypes member)
Example
Delete column¶
delete_column
Delete the column whose key is column_key in the table table_name. You cannot delete the first column as explained here.
Output Dict containing a single success key with the result of the operation (throws an error if no table named table_name exists, if no column with the key column_key exists or if you try to delete the first column)
Example
Single- and/or multiple-select columns specific methods¶
Add column options¶
add_column_options
Used by both "single select" or "multiple select"-type columns to add new options to the column column_name of the table table_name.
-
options: list of option dict containing the following keys:-
name: displayed text of the option -
color: background color of the option (hex code) -
textColor: text color of the option (hex code)
-
Output Dict containing a single success key with the result of the operation (throws an error if no table named table_name exists, if no column named column_name exists or if options is invalid)
Example
from seatable_api import Base, context
base = Base(context.api_token, context.server_url)
base.auth()
base.add_column_options('Table1', 'My choices', [
{"name": "ddd", "color": "#aaa", "textColor": "#000000"},
{"name": "eee", "color": "#aaa", "textColor": "#000000"},
{"name": "fff", "color": "#aaa", "textColor": "#000000"},
])
Add column cascade settings¶
add_column_cascade_settings
Used by "single select"-type column, to condition the available options (see cascading in the user manual or in the API Reference) of a child column child_column based on the options of a parent column parent_column.
-
child_column: name of the column you want to condition the available options forparent_column: name of the parent column whose options will be used to condition the available options of the child columncascade_settings: cascade dict using the following structure:-
each key is the
nameof an option from the parent column -
each corresponding value is a list of the names of every allowed options from the child column
-
Output Dict containing a single success key with the result of the operation (throws an error if no table named table_name exists, if no column named child_column or parent_column exists or if cascade_settings is invalid)
Example
from seatable_api import Base, context
base = Base(context.api_token, context.server_url)
base.auth()
base.add_column_cascade_settings("Table1", "Child", "Parent", {
"aaa": ["aaa-1", "aaa-2"], # (1)!
"bbb": ["bbb-1", "bbb-2"],
"ccc": ["ccc-1", "ccc-2"]
})
- If
aaais selected in the parent column, the available options for the child column will beaaa-1andaaa-2