Rows¶
Global structure¶
Here is the global structure of a row object:
{
"_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"
}
]
}
Please note the specific format for link-type columns (structure of the array objects for key link):
-
display_value: Value displayed in the cell -
row_id: id of the linked row in the other table
Get Row(s)¶
getRow
Get a single row by its ID.
Output Single row object
Example
getRows
Get all rows displayed in a view.
Output Array of row objects
Example
listRows
Get rows with optional sorting and pagination. Particularly useful for large tables.
Output Array of row objects
Example
getGroupedRows
Get rows grouped according to the view's grouping settings. Only available in SeaTable scripts.
Output Array of group objects, each containing a rows array
Example
query
Use SQL to query a base. Most SQL syntax is supported -- see the SQL Reference for details.
Backticks for special names
Escape table or column names that contain spaces or special characters with backticks: SELECT * FROM `My Table`
Output Array of row objects
Example
filter
Filter rows using a filter expression. Returns a QuerySet with chainable methods. Only available in SeaTable scripts.
Output QuerySet object
Example
// Get all rows where status is "Done"
const querySet = base.filter('Table1', 'Default View', 'Status = "Done"');
const rows = querySet.all();
const count = querySet.count();
const first = querySet.first();
QuerySet methods: .all(), .count(), .first(), .last(), .get(filter), .filter(filter), .delete(), .update(rowData)
Add Row(s)¶
appendRow
Append a new row to the end of a table.
Set applyDefault to true to use default column values for unspecified columns.
Example
insertRow
Insert a row after a specific anchor row.
Example
batchAppendRows
Append multiple rows at once. More efficient than calling appendRow in a loop.
Example
Update Row(s)¶
updateRow
Update a single row identified by its row ID.
In scripting context, you can also pass a row object instead of a row ID.
Example
modifyRows
Update multiple rows at once in scripting context. Pass two arrays: the rows to update and the corresponding update data.
Example
const table = base.getTableByName('Table1');
const rows = base.getRows(table, base.getViewByName(table, 'Default View'));
const selectedRows = rows.filter(row => row['Status'] === 'Open');
const updates = selectedRows.map(() => ({'Status': 'Archived'}));
base.modifyRows(table, selectedRows, updates);
batchUpdateRows
Update multiple rows at once. Each entry specifies a row ID and the data to update.
Example
Delete Row(s)¶
deleteRow
Delete a single row by its ID.
Example