Basic structure¶
The JavaScript script runs directly in the current browser and is suitable for simple data processing. JavaScript does not require any authentication.
Two JavaScript APIs in SeaTable
SeaTable offers two different ways to use JavaScript with SeaTable. You can executing a JS-Script directly in SeaTable and there is a JavaScript Client API. The functions are similar but not identical. If you want to use a JavaScript in SeaTable, stay at this section, otherwise switch to the Client APIs.
Interact with your base¶
JavaScript provide pre-defined objects, corresponding methods of this objects and utilities. On top, normal JavaScript operations like console.log
or calculations are working as usual.
Let's beginn¶
Let's make this concrete and let us look at some basic examples.
- Jump to your seatable webinterface
- Create a new Script of the type
Javascript
- Copy the following code
- Run the script
You will learn from these examples, that it is quite easy to read, output and even manipulate the data of a base inside SeaTable with the predefined objects and the corresponding methods.
-
base
is the predefined-object provided by SeaTable containing all bases of a base.getTables()
is the function to get all bases from the objectbase
.
-
output
is also a predefined-object provided by SeaTable.length
is just a normal operation in JavaScript.
As you can see, the script will output the number of tables in your base. Read the comments behind the two lines to get more information about the difference between a predefined object, a method of this object and an ordinary JavaScript function.
const table = base.getTableByName('Table1'); // (1)!
const view = base.getViewByName(table, 'Default View'); // (2)!
const rows = base.getRows(table, view); // (3)!
for (var i=0; i<rows.length; i++) { // (4)!
const row = rows[i];
output.text(row['Name']);
}
- get the content of the table
Table1
. - get the content of the view
Default View
. - get the row of this view
Default View
in this tableTable1
. - iterate over all rows and print them
This time, we will get the Name
of all columns in the table Table1
and the view Default View
.