
## View

A view belonging to a [table](/developers/scripting/api/table.md) in your [base](/developers/scripting/api/base.md). Each table has at least one
view.

Get views using [table.getView()](/developers/scripting/api/table.md#get-view).

```js
let table = base.getTable("Tasks");
let view = table.getView("Todo");
console.log(view);
```

### id

```js
string
```

The unique ID of this view.

```js
// Show a view id
let table = base.getTable("Projects");
let view = table.getView("By Launch Date");
console.log(`View id: ${view.id}`);
```

### name

```js
string
```

The name of the view.

```js
// Show a view name
let table = base.getTable("People");
let view = table.getView("Grid View");
console.log(`View name: ${view.name}`);
```

### type

```js
'grid' | 'form' | 'calendar' | 'gallery' | 'kanban'
```

The type of the view, such as Grid, Calendar, or Kanban.

```js
// 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

```js
string
```

The URL for the view. You can visit this URL in the browser to be taken to the view in the Airtable
UI.

```js
// 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

> See also: [RecordQueryResult](/developers/scripting/api/recordqueryresult.md)
> See also: [Field](/developers/scripting/api/field.md)
```js
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](/developers/scripting/api/field.md), 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](/developers/scripting/api/record.md) 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.

```js
// 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);
```

```js
// 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

```js
async function (
    recordId: string,
    options?: {
        fields?: Array<Field | string>,
    },
) => Promise<Record | null>;
```

| Parameter name | Description |
|---|---|
| `recordId` | The ID of the [record](/developers/scripting/api/record.md) 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](/developers/scripting/api/field.md), 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.
