View
A view belonging to a table in your base. Each table has at least one view.
Get views using table.getView().
Example
let table = base.getTable("Tasks");let view = table.getView("Todo");console.log(view);
id
typedef
string
The unique ID of this view.
Example
// Show a view idlet table = base.getTable("Projects");let view = table.getView("By Launch Date");console.log(`View id: ${view.id}`);
name
typedef
string
The name of the view.
Example
// Show a view namelet table = base.getTable("People");let view = table.getView("Grid View");console.log(`View name: ${view.name}`);
type
typedef
'grid' | 'form' | 'calendar' | 'gallery' | 'kanban'
The type of the view, such as Grid, Calendar, or Kanban.
Example
// show the type of every view in "Tasks"for (let view of base.getTable("Tasks").views) {console.log(`View "${view.name}" has type "${view.type}".`);}
url
typedef
string
The URL for the view. You can visit this URL in the browser to be taken to the view in the Airtable UI.
Example
// Show a link to open every view in "Projects"for (let view of base.getTable("Projects").views) {console.log(`[Click to open ${view.name}](${view.url})`);}
selectRecordsAsync
function
async function (options?: {sorts?: Array<{field: Field | string,direction?: 'asc' | 'desc',}>,fields?: Array<Field | string>,recordIds?: Array<string>,}) => Promise<RecordQueryResult>;
Parameter name | Description |
---|---|
options | Optional. Options for the query. |
options.sorts | Optional. Pass an array of sorts to control the order of records within the query result. The first sort in the array has the highest priority. If you don't specify sorts, the query result will use the order of records shown in the Airtable UI for this view. |
options.fields | Optional. Generally, it's a good idea to load as little data into your script as possible - Airtable bases can get pretty big. The fields option lets you make sure that only data relevant to you is loaded. You can specify fields with a Field, by ID, or by name. Leaving out this option is discouraged, but will be supported for now. Before this changes, we will post a potential deprecation timeline. Note: primary field is not included by default. |
options.recordIds | Optional. The IDs of the records to return. If provided, only the records identified in this array will be returned. If none of the IDs are found, an empty result will be returned. A maximum of 100 records can be requested at a time. |
Select records from the view. This action is asynchronous: you must add await
before each call to this method.
Example
// query for every record in "By Project"let table = base.getTable("People");let view = table.getView("By Project");let query = await view.selectRecordsAsync({fields: table.fields});console.log(query);
Example
// query for given fields in every record in "Kanban"let table = base.getTable("Tasks");let view = table.getView("Kanban");let query = await view.selectRecordsAsync({fields: ["Priority", "Status"],sorts: [// sort by "Priority" in ascending order...{field: "Priority"},// then by "Status" in descending order.{field: "Status", direction: "desc"},]});// print ID & "Priority" from each record:for (let record of query.records) {console.log(`**${record.id}**${record.getCellValueAsString("Priority")}`);}
selectRecordAsync
function
async function (recordId: string,options?: {fields?: Array<Field | string>,},) => Promise<Record | null>;
Parameter name | Description |
---|---|
recordId | The ID of the record to return. |
options | Optional. Options for the query. |
options.fields | Optional. The fields option lets you make sure that only data relevant to you is loaded. You can specify fields by passing in a Field, ID, or name. When selecting a single record, requesting all fields doesn't have the potential problem of loading large amounts of data. |
Select a single record from the view. This action is asynchronous: you must add await
before each call to this method. If the specified record cannot be found, null
will be returned.