### Example: Get All Fields Source: https://lark-base-team.github.io/js-sdk-docs/en/api/table This example retrieves the list of fields from the table. ```typescript const fieldList = await table.getFieldList(); ``` -------------------------------- ### Get All Tables Example (TypeScript) Source: https://lark-base-team.github.io/js-sdk-docs/zh/api/base Illustrates how to fetch all available tables in the current base. ```typescript const tableList = await base.getTableList(); ``` -------------------------------- ### Get All Table Metadata Example (TypeScript) Source: https://lark-base-team.github.io/js-sdk-docs/zh/api/base Demonstrates how to fetch metadata for all tables in the current base. ```typescript const tableMetaList = await base.getTableMetaList(); ``` -------------------------------- ### Example: Get Attachment Field Meta List Source: https://lark-base-team.github.io/js-sdk-docs/en/api/table This example demonstrates how to retrieve a list of attachment field meta data, specifying `IAttachmentFieldMeta` for type checking and intellisense support. ```typescript const attachmentMetaList = await table.getFieldMetaListByType(FieldType.Attachment) ``` -------------------------------- ### Example: Get All Options from Single Select Field Source: https://lark-base-team.github.io/js-sdk-docs/zh/api/field/singleSelect Shows how to retrieve all options currently configured for a single select field using the `getOptions` method. ```typescript await singleSelectField.getOptions(); ``` -------------------------------- ### Example: Get Field by Name with Type Source: https://lark-base-team.github.io/js-sdk-docs/en/api/table This example retrieves a field by its name, defining the expected type as `IAttachmentField` for proper type checking and intellisense. ```typescript const field = await table.getFieldByName(name); ``` -------------------------------- ### Get Attachment URLs from Field Source: https://lark-base-team.github.io/js-sdk-docs/en/api/guide This TypeScript example shows how to retrieve the actual URLs for attachments associated with a specific record using the getAttachmentUrls method of an IAttachmentField. It illustrates how field-centric methods abstract complex multi-step processes for obtaining data, making development more convenient. ```typescript const attachmentUrls = await attachmentField.getAttachmentUrls(recordId); ``` -------------------------------- ### Example: Get Field by ID with Type Source: https://lark-base-team.github.io/js-sdk-docs/en/api/table This example retrieves a field by its ID, defining the expected type as `IAttachmentField` for proper type checking and intellisense. ```typescript const field = await table.getFieldById(id); ``` -------------------------------- ### Example: Get Multiple Records with Pagination Source: https://lark-base-team.github.io/js-sdk-docs/zh/api/table Shows how to retrieve the active table and then fetch records from it using `getRecords` with a specified `pageSize`. This example fetches up to 5000 records. ```typescript // 首先使用 getActiveTable 方法获取了当前用户选择的 table(用户当前编辑的数据表) const table = await bitable.base.getActiveTable(); const records = await table.getRecords({ pageSize: 5000 }) ``` -------------------------------- ### Example: Call switchToTable Method Source: https://lark-base-team.github.io/js-sdk-docs/zh/api/ui Illustrates how to asynchronously switch the UI to a specified table using its ID with the `bitable.ui.switchToTable` method. ```TypeScript await bitable.ui.switchToTable('table_id'); ``` -------------------------------- ### Example: Get Field by ID or Name with Type Source: https://lark-base-team.github.io/js-sdk-docs/en/api/table This example retrieves a field by its ID or name, defining the expected type as `IAttachmentField` for proper type checking and intellisense. ```typescript const field = await table.getField(idOrName); ``` -------------------------------- ### Get Table by Name Example (TypeScript) Source: https://lark-base-team.github.io/js-sdk-docs/zh/api/base Demonstrates how to retrieve a table object by its name using the `getTableByName` method. ```typescript const table = await base.getTableByName('Table_For_Test'); ``` -------------------------------- ### Example: Select Record IDs and Retrieve Full Records Source: https://lark-base-team.github.io/js-sdk-docs/zh/api/ui Provides a comprehensive example of using `selectRecordIdList`. It first obtains the current table and view selection, then calls the interactive record selection, and finally iterates through the returned record IDs to fetch and store the full record objects from the active table. ```TypeScript const { tableId, viewId } = await bitable.base.getSelection(); const recordIdList = await bitable.ui.selectRecordIdList(tableId, viewId); const table = await bitable.base.getActiveTable(); const recordValList = []; for (const recordId of recordIdList) { recordValList.push(await table.getRecordById(recordId)); } ``` -------------------------------- ### Example: Call switchToView Method Source: https://lark-base-team.github.io/js-sdk-docs/zh/api/ui Demonstrates how to asynchronously switch the UI to a specified view within a table using the `bitable.ui.switchToView` method, providing both table and view IDs. ```TypeScript await bitable.ui.switchToView('table_id', 'view_id'); ``` -------------------------------- ### Get Field by ID (TypeScript Example) Source: https://lark-base-team.github.io/js-sdk-docs/zh/api/table An example demonstrating how to retrieve a field by its ID or name using the `getFieldById` method. ```typescript const field = await table.getFieldById(idOrName); ``` -------------------------------- ### Get Table Metadata by ID Example (TypeScript) Source: https://lark-base-team.github.io/js-sdk-docs/zh/api/base Shows how to obtain table metadata by providing a table ID. ```typescript const tableMeta = await base.getTableMetaById('t_id'); ``` -------------------------------- ### Example: Get All Record IDs Source: https://lark-base-team.github.io/js-sdk-docs/zh/api/table Demonstrates a simple call to `table.getRecordIdList()` to obtain all record identifiers present in the table. ```typescript const recordIdList = await table.getRecordIdList(); ``` -------------------------------- ### Get Current Environment Information Source: https://lark-base-team.github.io/js-sdk-docs/zh/api/bridge Asynchronously retrieves detailed information about the current operating environment, including the product type (e.g., 'lark' or 'feishu'). ```APIDOC getEnv(): Promise; type Product = 'lark' | 'feishu'; interface Env { product: Product; } ``` ```typescript const env = await bitable.bridge.getEnv(); // { product: 'feishu' } ``` -------------------------------- ### Example: Get Record by ID Source: https://lark-base-team.github.io/js-sdk-docs/zh/api/table Demonstrates how to retrieve the list of all record IDs using `table.getRecordIdList()` and then fetch a specific record using its ID with `table.getRecordById()`. ```typescript const recordIdList = await table.getRecordIdList(); // 获取 recordId 列表 const recordValue = await table.getRecordById(recordIdList[0]); ``` -------------------------------- ### Retrieve Table in Old JS SDK Version (TypeScript) Source: https://lark-base-team.github.io/js-sdk-docs/en/update This code shows the previous method for retrieving a table in the JS SDK. It involves first getting the `tableId` from the current selection and then using `getTableById()` to fetch the table object. This pattern was common but has since been optimized. ```typescript const { tableId } = await bitable.base.getSelection(); const table = await bitable.base.getTableById(tableId); ``` -------------------------------- ### Create and Add Attachment Cell to Table Source: https://lark-base-team.github.io/js-sdk-docs/en/api/guide This TypeScript example demonstrates how to obtain an attachment field using its ID, create an attachment cell from a file, and then add this cell as a new record to the table. It highlights the use of type parameters like IAttachmentField for better type hinting and the flexibility of table.addRecord to accept single cells or arrays of cells. ```typescript const attachmentField = await table.getField(fieldId); const attachemntCell = await attachmentField.createCell(file); await table.addRecord(attachmentCell); ``` -------------------------------- ### Add Attachment Data to Record in New JS SDK (TypeScript) Source: https://lark-base-team.github.io/js-sdk-docs/en/update This example demonstrates the improved CRUD operation for adding attachment data to a record. It involves retrieving the attachment field, creating an attachment cell from a `File` object, and then adding this cell to the table as a new record. This simplifies file handling by integrating `createCell`. ```typescript const attachmentField = await table.getField(attachmentFieldId); const attachmentCell = await attachmentField.createCell(File); const recordId = await table.addRecord(attachmentCell); ``` -------------------------------- ### Example: Get Cell Value Source: https://lark-base-team.github.io/js-sdk-docs/zh/api/cell Illustrates how to retrieve an existing "Cell" from a "Field" and then access its value using the "getValue" method. This is useful for reading data from the table. ```typescript const cell = await field.getCell(recordOrId); const value = await cell.getValue(); ``` -------------------------------- ### Example: Iterate Through Record List Source: https://lark-base-team.github.io/js-sdk-docs/zh/api/table Illustrates how to get the list of records using `table.getRecordList()` and then iterate through each record to access cell values by field using `record.getCellByField()` and `cell.getValue()`. ```typescript const recordList = await table.getRecordList(); for (const record of recordList) { const cell = await record.getCellByField(fieldId); const val = await cell.getValue(); } ``` -------------------------------- ### Add New Table Example (TypeScript) Source: https://lark-base-team.github.io/js-sdk-docs/zh/api/base Demonstrates how to add a new table to the base with a given name and retrieve its ID and index. ```typescript const { tableId, index } = await bitable.base.addTable({ name: '测试添加数据表' }) ``` -------------------------------- ### Example: Create MultipleSelect Cell Source: https://lark-base-team.github.io/js-sdk-docs/zh/api/field/multipleSelect Demonstrates how to use the `createCell` method to create a new cell for a multiple-select field. In this example, a simple string value is passed, which will be transformed into the appropriate multiple-select format. ```typescript await multiSelectField.createCell('test option'); ``` -------------------------------- ### Get List of Views (TypeScript) Source: https://lark-base-team.github.io/js-sdk-docs/en/api/table Retrieves a list of all available views. ```typescript getViewList: () => Promise; ``` -------------------------------- ### Get Filter Information (TypeScript) Source: https://lark-base-team.github.io/js-sdk-docs/en/api/view/grid Get the current filter information. ([IFilterInfo definition](./../view#ifilterinfo)) ```typescript getFilterInfo(): Promise; ``` ```APIDOC getFilterInfo(): Promise ``` -------------------------------- ### Obtain UI Module Instance Source: https://lark-base-team.github.io/js-sdk-docs/en/api/ui Demonstrates how to get an instance of the `UI` module from the `bitable` object, which is necessary to perform UI-related operations within the Base JS SDK. ```typescript const ui = bitable.ui; ``` -------------------------------- ### Lark Base JS SDK Core API Overview Source: https://lark-base-team.github.io/js-sdk-docs/en/api/guide This section provides a high-level overview of the main entry point (`bitable`) and its core modules (`base`, `ui`, `bridge`) within the Lark Base JS SDK. It outlines the primary function of each module, particularly highlighting the `base` module's role in table manipulation. ```APIDOC bitable: Description: The main entry point for all APIs in the Lark Base JS SDK. Properties: base: Description: Contains APIs for manipulating multidimensional tables, such as CRUD operations. Example Method: getActiveTable(): Description: Gets the currently selected table on the page. ui: Description: One of the three main properties of the bitable object. bridge: Description: One of the three main properties of the bitable object. ``` -------------------------------- ### Get Active Table in Base Module (TypeScript) Source: https://lark-base-team.github.io/js-sdk-docs/en/api/guide This TypeScript snippet demonstrates how to obtain the currently active table object using the `getActiveTable()` method from the `bitable.base` module. This is a common operation for interacting with the currently selected table in the Lark Base JS SDK. ```typescript import { bitable } from '@lark-base-open/js-sdk'; const table = await bitable.base.getActiveTable(); ``` -------------------------------- ### Initialize UI Module Instance Source: https://lark-base-team.github.io/js-sdk-docs/zh/api/ui Demonstrates how to obtain the `ui` module instance from the `bitable` object, which provides access to user interaction capabilities within the Base JS SDK. ```TypeScript const ui = bitable.ui; ``` -------------------------------- ### Example: Iterate Record List (TypeScript) Source: https://lark-base-team.github.io/js-sdk-docs/en/api/table Demonstrates how to retrieve a record list and then iterate through each record to access cell values by field ID. ```typescript const recordList = await table.getRecordList(); for (const record of recordList) { const cell = await record.getCellByField(fieldId); const val = await cell.getValue(); } ``` -------------------------------- ### Example: Get Attachment Fields Source: https://lark-base-team.github.io/js-sdk-docs/en/api/table Demonstrates a practical application of getFieldListByType to retrieve only attachment fields. By specifying IAttachmentField as the generic type, it ensures proper type checking and enhances intellisense support for the returned list. ```typescript const attachmentFieldList = await table.getFieldListByType(FieldType.Attachment); ``` -------------------------------- ### Get Sort Information (TypeScript) Source: https://lark-base-team.github.io/js-sdk-docs/en/api/view/grid Get the current sort information. ([ISortInfo definition](./../view#isortinfo)) ```typescript getSortInfo(): Promise; ``` ```APIDOC getSortInfo(): Promise ``` -------------------------------- ### API Reference: switchToView Method Source: https://lark-base-team.github.io/js-sdk-docs/en/api/ui Provides the signature and description for the `switchToView` method, which allows switching to a specific view within a table. ```typescript switchToView(tableId: string, viewId: string): Promise; ``` ```APIDOC switchToView: description: Switches to a specific view within a table. parameters: tableId: string - The ID of the table containing the view. viewId: string - The ID of the view to switch to. returns: Promise - A Promise that resolves to true if the switch was successful, false otherwise. ``` -------------------------------- ### Get Group Information (TypeScript) Source: https://lark-base-team.github.io/js-sdk-docs/en/api/view/grid Get group information ([IGroupInfo definition](./../view#igroupinfo)) ```typescript getGroupInfo(): Promise; ``` ```APIDOC getGroupInfo(): Promise ``` -------------------------------- ### Initialize Base JS SDK and Access Table Data Source: https://lark-base-team.github.io/js-sdk-docs/zh/start/core This TypeScript snippet demonstrates how to import the `bitable` object, retrieve the active table, and then filter fields by type, specifically showing how to get attachment fields. It illustrates basic SDK initialization and data access patterns. ```typescript import { bitable } from '@lark-base-open/js-sdk' const table = await bitable.base.getActiveTable(); const attachmentFieldList = await table.getFieldListByType(FieldType.Attachment); ``` -------------------------------- ### GalleryView Get Metadata Method Source: https://lark-base-team.github.io/js-sdk-docs/zh/api/view/gallery Asynchronously retrieves the metadata for the view. ```TypeScript getMeta(): Promise; ``` -------------------------------- ### Get Filter Information (TypeScript) Source: https://lark-base-team.github.io/js-sdk-docs/en/api/view/kanban Retrieves the current filter information as a Promise resolving to `IFilterInfo` or `null`. ```typescript getFilterInfo(): Promise; ``` -------------------------------- ### Example: Get MultipleSelect Cell Source: https://lark-base-team.github.io/js-sdk-docs/zh/api/field/multipleSelect Illustrates how to obtain a cell for a multiple-select field from a specific record. This snippet first retrieves the active table and its records, then gets the cell for the first record. ```typescript const table = await bitable.base.getActiveTable(); const recordList = await table.getRecordList(); const cell = await multiSelectField.getCell(recordList[0]); ``` -------------------------------- ### Old Method to Get Table by ID (TypeScript) Source: https://lark-base-team.github.io/js-sdk-docs/zh/update Illustrates the previous boilerplate method for obtaining a table. It requires first getting the `tableId` from the current selection (`bitable.base.getSelection()`) and then using `getTableById` to retrieve the table object. This pattern was common in older SDK versions. ```TypeScript const { tableId } = await bitable.base.getSelection(); const table = await bitable.base.getTableById(tableId); ``` -------------------------------- ### Bitable API Module Concepts Source: https://lark-base-team.github.io/js-sdk-docs/en/start/core This documentation outlines the core modules of the `bitable` API, explaining their individual responsibilities and how they interact within the multidimensional table context. It covers data structures, UI components, and application-level interfaces. ```APIDOC bitable: Description: The entry point of the API. Modules like base, ui, bridge, etc., are mounted as properties. base: Description: Can be understood as a collection of multiple `tables`. Provides API to get the corresponding `table` and includes application-level APIs such as file upload. table: Description: A collection of data, similar to tables in databases. Contains `fields` and `records`. Also includes the concept of `views`. Properties: fields: (unordered at table level) records: views: field: Description: Contains many different field types (e.g., `IAttachmentField`, `ICurrencyField`). Provides methods for field operations and setting field properties (e.g., adding options for multi-select/single-select fields). Methods: addOptions: (for multi-select/single-select fields) createCell: (to create a cell, which can be passed to `table.addRecord`) record: Description: Mainly used to retrieve data. Can work together with `field` to retrieve `cells`. cell: Description: Represents a single cell, which is the data of a specific cell in a `record` or `field`. Supports creation by calling `field.createCell`. Methods: createCell: (from `field` module) getValue: (after insertion into table, real-time) setValue: (after insertion into table, real-time) view: Description: Determines the display method (order/visibility) of `fields` and `records` in the current view (table view/board view). Information retrieved at this layer often matches the current display content. Properties: fields: (ordered according to view) records: (ordered according to view) ui: Description: Responsible for the API of the plugin's display window UI, related to the application capabilities of the plugin. bridge: Description: Mainly provides application-level interfaces, such as theme switching event notification, which are related to the application capabilities. ``` -------------------------------- ### Example: Get Cell Value from Selection Source: https://lark-base-team.github.io/js-sdk-docs/zh/api/table Illustrates how to get the currently selected cell's field and record IDs using `bitable.base.getSelection()`, then retrieve its value using `table.getCellValue`. ```typescript // 光标选中数据表中的单元格 const { fieldId, recordId } = await bitable.base.getSelection(); const cellValue = table.getCellValue(fieldId, recordId); ``` -------------------------------- ### API: Get SingleSelect Cell Source: https://lark-base-team.github.io/js-sdk-docs/zh/api/field/singleSelect Documents the `getCell` method for `ISingleSelectField`, which retrieves a specific cell from the single-select field based on a record object or its ID. The method returns a Promise that resolves to an `ICell` object. An example shows how to get a cell from the first record in a table. ```APIDOC getCell: (recordOrId: IRecordType | string) => Promise; ``` ```typescript const table = await bitable.base.getActiveTable(); const recordList = await table.getRecordList(); const cell = await singleSelectField.getCell(recordList[0]); ``` -------------------------------- ### API Reference: switchBlock Method Source: https://lark-base-team.github.io/js-sdk-docs/en/api/ui Provides the signature and description for the `switchBlock` method, used to switch the current view to a different block like a Dashboard. ```typescript switchBlock(blockId: string): Promise; ``` ```APIDOC switchBlock: description: Switches to a different block, such as a Dashboard. parameters: blockId: string - The ID of the block to switch to. returns: Promise - A Promise that resolves to true if the switch was successful, false otherwise. ``` -------------------------------- ### Get Current Environment API (TypeScript) Source: https://lark-base-team.github.io/js-sdk-docs/en/api/bridge Retrieves information about the current operating environment. The `Env` interface includes the `product` type, which can be 'lark' or 'feishu', indicating the platform. ```typescript getEnv(): Promise; type Product = 'lark' | 'feishu'; interface Env { product: Product; } ``` -------------------------------- ### Example: Set MultipleSelect Cell Value Source: https://lark-base-team.github.io/js-sdk-docs/zh/api/field/multipleSelect Shows how to set the value of a multiple-select field for a specific record. This example demonstrates passing an array of option IDs to update the field's value for the first record in the table. ```typescript const table = await bitable.base.getActiveTable(); const recordIdList = await table.getRecordIdList(); await multiSelectField.setValue(recordIdList[0], ['option_id1', 'option_id2']); // 传入选项 id ``` -------------------------------- ### Import Currency Conversion Utilities Source: https://lark-base-team.github.io/js-sdk-docs/en/start/example Imports necessary constants and functions for currency conversion. `CURRENCY` likely contains a list of supported currency codes, and `getExchangeRate` is an asynchronous function to fetch exchange rates from an external API, essential for performing the actual conversion. ```typescript import { CURRENCY } from './const'; import { getExchangeRate } from './exchange-api'; ``` -------------------------------- ### Get All Field Options Source: https://lark-base-team.github.io/js-sdk-docs/en/api/field/multipleSelect Retrieves all existing options for the field. The returned options include their ID, name, and color. ```typescript getOptions: () => Promise; ``` ```typescript interface ISelectFieldOption { id: string; name: string; color: number; } ``` ```APIDOC Method: getOptions Description: Gets all the options for the field. Parameters: None Returns: Promise Type Definition: ISelectFieldOption id: string - Unique identifier for the option. name: string - Display name of the option. color: number - Color code of the option. ``` -------------------------------- ### Example: Get ModifiedTime Field Value Source: https://lark-base-team.github.io/js-sdk-docs/zh/api/field/modifiedTime Demonstrates calling the `getValue` method on a `modifiedTimeField` instance to retrieve the timestamp for a record identified by 'r_id'. ```typescript await modifiedTimeField.getValue('r_id'); ``` -------------------------------- ### Example: Add New Record with Created Cells Source: https://lark-base-team.github.io/js-sdk-docs/zh/api/cell Illustrates how to create multiple "Cell" instances of different types (e.g., attachment, single select) and then add them together as a new record to a "Table". This demonstrates the typical workflow for inserting new data. ```typescript const attachmentCell = await attachmentField.createCell(imageFileList); const singleSelectCell = await singleSelectField.createCell('option1'); const recordId = await table.addRecord([attachmentCell, singleSelectCell]); ``` -------------------------------- ### GalleryView Get Name Method Source: https://lark-base-team.github.io/js-sdk-docs/zh/api/view/gallery Asynchronously retrieves the name of the view. ```TypeScript getName(): Promise; ``` -------------------------------- ### Example: Set User Field Value Source: https://lark-base-team.github.io/js-sdk-docs/zh/api/field/user Illustrates how to set the value of a user field, demonstrating setting multiple user IDs for a record. ```typescript await userField.setValue([ { id: 'ou_xxxx1' }, { id: 'ou_xxxx2' } ]); ``` -------------------------------- ### Get Sort Information (TypeScript) Source: https://lark-base-team.github.io/js-sdk-docs/en/api/view/kanban Retrieves the current sorting conditions as a Promise resolving to an array of `ISortInfo`. ```typescript getSortInfo(): Promise; ``` -------------------------------- ### KanbanView.applySetting() Method Source: https://lark-base-team.github.io/js-sdk-docs/zh/api/view/kanban Submits the current view configurations, such as grouping, filtering, and sorting settings, to synchronize them with other users. This method returns a Promise that resolves when the settings are applied. ```TypeScript applySetting(): Promise; ``` -------------------------------- ### Example: Get ModifiedTime Field Cell Source: https://lark-base-team.github.io/js-sdk-docs/zh/api/field/modifiedTime Demonstrates calling the `getCell` method on a `modifiedTimeField` instance to obtain the cell object for a record identified by 'r_id'. ```typescript await modifiedTimeField.getCell('r_id'); ``` -------------------------------- ### Implement Core Currency Conversion Logic (Partial) Source: https://lark-base-team.github.io/js-sdk-docs/en/start/example Begins the implementation of the `transform` function. It checks if a field and currency are selected, retrieves the active table and the selected currency field, sets the new currency code, and fetches the exchange rate. The snippet is partial, indicating further logic for record iteration and value conversion is required. ```typescript const transform = async () => { // If the user hasn't selected a currency or conversion field, do nothing if (!selectFieldId || !currency) return; const table = await bitable.base.getActiveTable(); // Get the currency field, using the ICurrencyField interface to indicate that we are getting a currency field // With TypeScript, we get a lot of type hints to help with development when we restrict the type of the field const currencyField = await table.getField(selectFieldId); const currentCurrency = await currencyField.getCurrencyCode(); // Set the currency code await currencyField.setCurrencyCode(currency); // Get the exchange rate for the currency const ratio = await getExchangeRate(currentCurrency, currency); if (!ratio) return; // First, get the recordId ``` -------------------------------- ### Example: Get User Field Cell Source: https://lark-base-team.github.io/js-sdk-docs/zh/api/field/user Demonstrates how to retrieve a user field cell using a record ID with the getCell method. ```typescript await userField.getCell('r_id'); ``` -------------------------------- ### GalleryView Apply Setting Method Source: https://lark-base-team.github.io/js-sdk-docs/zh/api/view/gallery Asynchronously applies and synchronizes view configurations such as grouping, filtering, and sorting with other users. ```TypeScript applySetting(): Promise; ``` -------------------------------- ### Prepare Currency Conversion Button and Function Source: https://lark-base-team.github.io/js-sdk-docs/en/start/example Adds a 'transform' button to the UI, which, when clicked, will trigger the `transform` asynchronous function. This function will encapsulate the core currency conversion logic, allowing users to initiate the conversion process after making their selections. ```typescript const transform = async () => { } return
Select Field
``` -------------------------------- ### GalleryView Get Filter Info Method Source: https://lark-base-team.github.io/js-sdk-docs/zh/api/view/gallery Asynchronously retrieves the current filter information applied to the view. Refer to IFilterInfo definition for details. ```TypeScript getFilterInfo(): Promise; ``` -------------------------------- ### Initialize Base Module Source: https://lark-base-team.github.io/js-sdk-docs/en/api/base Initializes the `base` module from the `bitable` SDK, providing access to base-level operations. This is the first step to interact with the base. ```typescript const base = bitable.base; ``` -------------------------------- ### Apply Kanban View Settings Source: https://lark-base-team.github.io/js-sdk-docs/en/api/view/kanban Asynchronously submits and applies the current view configuration, such as grouping, filtering, and sorting settings. This action synchronizes the changes across all users interacting with the view. ```typescript applySetting(): Promise; ``` -------------------------------- ### Get Current Theme Mode Source: https://lark-base-team.github.io/js-sdk-docs/zh/api/bridge Asynchronously retrieves the current theme mode of the application. The theme can be 'LIGHT' or 'DARK'. ```APIDOC getTheme(): Promise; enum ThemeModeType { LIGHT = "LIGHT", DARK = "DARK" } ``` ```typescript const theme = await bitable.bridge.getTheme(); // 'LIGHT' ``` -------------------------------- ### Base JS SDK Core Module API Overview Source: https://lark-base-team.github.io/js-sdk-docs/zh/start/core This API documentation provides a conceptual overview of the main modules within the Base JS SDK, detailing their purpose, relationships, and key functionalities. It serves as a guide to understanding the SDK's architecture. ```APIDOC bitable: API entry point for the SDK. - base: Module representing a collection of tables. Provides APIs to obtain specific tables and handle file uploads. - table: Module representing a data collection, similar to a database table. Contains `field`, `record`, and `view` concepts. Data retrieval at this level is often unordered as it lacks display context. - field: Module containing various field types (e.g., IAttachmentField, ICurrencyField). Offers methods for field operations and property settings. Recommended for data manipulation in conjunction with records. - record: Module primarily used for data retrieval. Works with `field` to access `cell` data. - cell: Represents a single unit of data within a `record`/`field`. Can be created using `field.createCell()`. Once inserted into a table, it automatically links to a `record`, and its `getValue`/`setValue` methods become real-time. - view: Module determining the display of `field`s and `record`s within a specific view (e.g., table view, kanban view). Data retrieval at this level reflects the current display order and visibility. - ui: Module responsible for the plugin's UI display window APIs, related to the plugin's application capabilities. - bridge: Module providing application-layer interfaces, such as theme switching event notifications. Similar to the `ui` module, it relates to application capabilities. ``` -------------------------------- ### Get Field by Name in TypeScript Source: https://lark-base-team.github.io/js-sdk-docs/zh/api/table Retrieves a field by its name. It is recommended to specify the field type (e.g., in the example) for improved type hinting. ```APIDOC getFieldByName: (name: string) => Promise; ``` ```typescript const field = await table.getFieldByName(idOrName); ``` -------------------------------- ### Example: Get User Field Value Source: https://lark-base-team.github.io/js-sdk-docs/zh/api/field/user Shows how to retrieve the value of a user field for a given record ID using the getValue method. ```typescript await userField.getValue('r_id'); ``` -------------------------------- ### Example: Set Cell Value Source: https://lark-base-team.github.io/js-sdk-docs/zh/api/cell Demonstrates how to create a new text "Cell" and then update its value using the "setValue" method. This shows a direct manipulation of a cell's content. ```typescript const cell = await textField.createCell('test'); cell.setValue('modify value'); ``` -------------------------------- ### Example: Get Geolocation Cell with getCell Source: https://lark-base-team.github.io/js-sdk-docs/zh/api/field/location Demonstrates how to use the getCell method on an ILocationField instance. It shows retrieving a geolocation cell by passing the record ID. ```typescript await locationField.getCell('r_id'); ``` -------------------------------- ### Example: Create User Field Cell Source: https://lark-base-team.github.io/js-sdk-docs/zh/api/field/user Shows how to use the createCell method to create a new cell for a user field, providing a user ID. ```typescript await userField.createCell({ id: 'ou_xxxx' }); ``` -------------------------------- ### Fetch Exchange Rate using Axios (TypeScript) Source: https://lark-base-team.github.io/js-sdk-docs/en/start/example This code defines an asynchronous function `getExchangeRate` that fetches real-time currency exchange rates from `api.exchangerate-api.com` using Axios. It takes a base currency and a target currency as input, returning the exchange rate or `undefined` if an error occurs or the rate is not found. The `ExchangeRatesResponse` interface defines the expected structure of the API response. ```typescript import axios from 'axios'; interface ExchangeRatesResponse { rates: { [key: string]: number; }; base: string; date: string; } export async function getExchangeRate(base: string, target: string): Promise { try { const response = await axios.get(`https://api.exchangerate-api.com/v4/latest/${base}`); const rate = response.data.rates[target]; if (!rate) { throw new Error(`Exchange rate not found for target currency: ${target}`); } return rate; } catch (error) { console.info(`Error fetching exchange rate: ${(error as any).message}`); } } ``` -------------------------------- ### Example: Get Option Type of Single Select Field Source: https://lark-base-team.github.io/js-sdk-docs/zh/api/field/singleSelect Shows how to retrieve whether the single select field uses static or dynamic options using the `getOptionsType` method. ```typescript await singleSelectField.getOptionsType(); ``` -------------------------------- ### Example: Fetching Selected Records with selectRecordIdList Source: https://lark-base-team.github.io/js-sdk-docs/en/api/ui Illustrates a practical use case of `selectRecordIdList` to obtain user-selected record IDs, then retrieves the full record objects from the active table for further processing. ```typescript const { tableId, viewId } = await bitable.base.getSelection(); const recordIdList = await bitable.ui.selectRecordIdList(tableId, viewId); const table = await bitable.base.getActiveTable(); const recordValList = []; for (const recordId of recordIdList) { recordValList.push(await table.getRecord(recordId)); } ``` -------------------------------- ### GalleryView Get Field Metadata List Method Source: https://lark-base-team.github.io/js-sdk-docs/zh/api/view/gallery Asynchronously retrieves an ordered list of field metadata for the view, reflecting the UI display order. ```TypeScript getFieldMetaList(): Promise; ``` -------------------------------- ### Apply Settings (TypeScript) Source: https://lark-base-team.github.io/js-sdk-docs/en/api/view/gallery Submits all pending grouping, filtering, and sorting settings to the view. This action synchronizes the configured settings with other users, making the changes visible and active. ```typescript applySetting(): Promise; ``` -------------------------------- ### Example: Delete Option from Single Select Field by ID Source: https://lark-base-team.github.io/js-sdk-docs/zh/api/field/singleSelect Demonstrates how to delete an option from a single select field by first getting all options and then using the ID of the first option found. ```typescript const options = await singleSelectField.getOptions(); await singleSelectField.deleteOption(options[0].id); ``` -------------------------------- ### Example: Get Geolocation Cell Value with getValue Source: https://lark-base-team.github.io/js-sdk-docs/zh/api/field/location Demonstrates how to use the getValue method on an ILocationField instance. It shows retrieving a geolocation cell's value by passing the record ID. ```typescript await locationField.getValue('r_id'); ``` -------------------------------- ### Retrieve Active Table in New JS SDK Version (TypeScript) Source: https://lark-base-team.github.io/js-sdk-docs/en/update This snippet illustrates the streamlined approach to retrieve the currently active table in the new JS SDK version. The `getActiveTable()` method allows for a single-step retrieval, simplifying common table access patterns. This optimizes the process compared to older versions. ```typescript const table = await bitable.base.getActiveTable(); ``` -------------------------------- ### Get Progress Field Cell Value (getValue) Source: https://lark-base-team.github.io/js-sdk-docs/zh/api/field/progress API documentation and example for the `getValue` method of `IProgressField`. This method retrieves the numeric value of a specific cell for a given record, returning a Promise that resolves to an `IOpenNumber`. ```APIDOC getValue: (recordOrId: IRecordType | string) => Promise; ``` ```typescript await progressField.getValue('r_id'); ``` -------------------------------- ### Render UI for Field and Currency Selection Source: https://lark-base-team.github.io/js-sdk-docs/en/start/example Defines a React component's render method that displays UI elements for selecting a currency field and a target currency. It includes a helper function `formatFieldMetaList` to prepare options for the `Select` components, allowing users to interactively choose conversion parameters. ```typescript const formatFieldMetaList = (metaList: ICurrencyFieldMeta[]) => { return metaList.map(meta => ({ label: meta.name, value: meta.id })); }; return
Select Field
``` -------------------------------- ### UI Module: switchToView Method Signature Source: https://lark-base-team.github.io/js-sdk-docs/zh/api/ui API definition for the `switchToView` method, which switches to a specified view within a given table. The view must belong to the table for the call to succeed. This asynchronous function takes both table and view IDs (strings) and returns a Promise resolving to a boolean indicating success. ```APIDOC switchToView(tableId: string, viewId: string): Promise; ``` -------------------------------- ### Get Progress Field Cell (getCell) Source: https://lark-base-team.github.io/js-sdk-docs/zh/api/field/progress API documentation and example for the `getCell` method of `IProgressField`. This method retrieves a specific cell associated with a given record (by ID or object), returning a Promise that resolves to an `ICell` object. ```APIDOC getCell: (recordOrId: IRecordType | string) => Promise; ``` ```typescript await progressField.getCell('r_id'); ``` -------------------------------- ### API Reference: selectRecordIdList Method Source: https://lark-base-team.github.io/js-sdk-docs/en/api/ui Provides the signature and description for the `selectRecordIdList` method, which enables users to interactively select records via a modal dialog, returning their IDs. ```typescript selectRecordIdList(tableId: string, viewId: string): Promise ``` ```APIDOC selectRecordIdList: description: Allows the user to interactively select records. This API will open a modal dialog for the user to choose records. Once the user has made their selection, the corresponding record IDs will be returned. parameters: tableId: string - The ID of the table from which to select records. viewId: string - The ID of the view within the table. returns: Promise - A Promise that resolves to an array of selected record IDs. ``` -------------------------------- ### Update Cell Value in Table Source: https://lark-base-team.github.io/js-sdk-docs/en/api/guide This TypeScript example demonstrates how to update the value of an existing cell in a table using the setValue method. Once a Cell is associated with a record, calling setValue will directly reflect the changes in the corresponding cell within the table. ```typescript await attachmentCell.setValue(newFile); ``` -------------------------------- ### Get Filter Information API Source: https://lark-base-team.github.io/js-sdk-docs/zh/api/view/grid 获取当前的筛选信息([IFilterInfo 定义](./../view#ifilterinfo))。 ```typescript getFilterInfo(): Promise; ``` -------------------------------- ### GanttView Class and Interface Definitions Source: https://lark-base-team.github.io/js-sdk-docs/zh/api/view/gantt Comprehensive API reference for the `GanttView` class and its associated `IGanttViewMeta` interface, detailing properties, methods, and their return types for interacting with Gantt chart views in the Base JS SDK. ```APIDOC GanttView Interface: Description: Represents a Gantt chart view within the Base JS SDK. Properties: id: string - The unique identifier of the current view. tableId: string - The identifier of the data table to which this view belongs. Methods: getName(): Promise - Retrieves the name of the view. getType(): Promise - Retrieves the type of the view, which is always Gantt. getMeta(): Promise - Retrieves the metadata for the view. showField(fieldId: string | string[]): Promise - Displays one or more fields in the view. hideField(fieldId: string | string[]): Promise - Hides one or more fields from the view. getFieldMetaList(): Promise - Retrieves an ordered list of field metadata relevant to the view. getVisibleRecordIdList(): Promise<(string | undefined)[]> - Retrieves a list of IDs for records currently visible in the view. getVisibleFieldIdList(): Promise - Retrieves a list of IDs for fields currently visible in the view. applySetting(): Promise - Submits and synchronizes view configurations such as grouping, filtering, and sorting with other users. getFilterInfo(): Promise - Retrieves the current filter information applied to the view. IGanttViewMeta Interface: Description: Defines the structure of the metadata for a Gantt view. Properties: id: string - The ID of the Gantt view. name: string - The name of the Gantt view. type: ViewType.Gantt - The type of the view, specifically Gantt. property: object - Contains detailed properties of the view. filterInfo: IFilterInfo | null - Information about the applied filter, or null if no filter is applied. sortInfo: ISortInfo[] - An array of sorting information. groupInfo: IGroupInfo[] - An array of grouping information. ``` -------------------------------- ### Get Only Mobile Data from Barcode Field (TypeScript) Source: https://lark-base-team.github.io/js-sdk-docs/zh/api/field/barcode This snippet demonstrates how to asynchronously retrieve only mobile-specific data from a barcode field instance. It utilizes the `getOnlyMobile()` method, which is part of the JavaScript SDK for interacting with form fields, ensuring that only mobile-related information is returned. ```typescript await barcodeField.getOnlyMobile(); ``` -------------------------------- ### Initialize Bridge Module in TypeScript Source: https://lark-base-team.github.io/js-sdk-docs/en/api/bridge Obtain an instance of the `Bridge` module from `bitable` to access plugin-level APIs such as persistent data access and theme information. This is the entry point for using the Bridge module's functionalities. ```typescript const bridge = bitable.bridge; ``` -------------------------------- ### Retrieve URL Field Value (TypeScript) Source: https://lark-base-team.github.io/js-sdk-docs/zh/api/field/url This TypeScript code snippet demonstrates how to fetch the value from a URL field. It first retrieves a list of all record IDs from the current table, then uses the first record ID to get the value of a 'urlField'. ```typescript const recordIdList = await table.getRecordIdList(); await urlField.getValue(recordIdList[0]); ``` -------------------------------- ### Example: Set Option Type of Single Select Field Source: https://lark-base-team.github.io/js-sdk-docs/zh/api/field/singleSelect Demonstrates how to set the single select field to use static options using the `setOptionsType` method. ```typescript await singleSelectField.setOptionsType(SelectOptionsType.STATIC); ``` -------------------------------- ### Example: Subscribe to Field Add Event Source: https://lark-base-team.github.io/js-sdk-docs/zh/api/table Illustrates how to use `onFieldAdd` to listen for field addition events. It shows subscribing to the event, then adding a new text field, demonstrating that the callback will be triggered upon field creation. ```typescript const off = table.onFieldAdd((event) => { console.log('event:', event); }) const fieldId = await table.addField({ // 新增一个多行文本类型的字段 type: FieldType.Text, name: 'field_test' }) ``` -------------------------------- ### Example: Querying Field Permissions with getPermission (TypeScript) Source: https://lark-base-team.github.io/js-sdk-docs/en/api/base Demonstrates how to use the getPermission method to query specific field permissions. It shows the structure of FieldPermissionParams and how to call the asynchronous method with appropriate parameters to check for editable permission. ```typescript const fieldInfo: FieldPermissionParams = { entity: PermissionEntity.Field, param: { tableId, fieldId, }, type: OperationType.Editable, } const hasPermission = await base.getPermission(params); ``` -------------------------------- ### Batch Get Records (TypeScript) Source: https://lark-base-team.github.io/js-sdk-docs/en/api/table Retrieves multiple records based on specified parameters, with a maximum of 500 records per request. Useful for paginated retrieval of records. ```typescript getRecords(param: IGetRecordsParams): Promise; ``` -------------------------------- ### Fetch Active Table and Currency Field Metadata on Component Mount Source: https://lark-base-team.github.io/js-sdk-docs/en/start/example Uses a `useEffect` hook to asynchronously fetch the active table and retrieve a list of currency field metadata upon component rendering. It updates the component's state with the table name and the list of currency fields, ensuring the UI has the necessary data for selection. ```typescript useEffect(() => { const fn = async () => { const table = await bitable.base.getActiveTable(); const tableName = await table.getName(); setInfo(`The table Name is ${tableName}`); setInfoType('success'); const fieldMetaList = await table.getFieldMetaListByType(FieldType.Currency); setMetaList(fieldMetaList); }; fn(); }, []); ``` -------------------------------- ### Get Progress Field Value Source: https://lark-base-team.github.io/js-sdk-docs/en/api/field/progress Gets the value of the Progress Field for the specified record. ```TypeScript getValue: (recordOrId: IRecordType | string) => Promise; ``` -------------------------------- ### Lark Base JS SDK: ICurrencyField Interface and Methods Source: https://lark-base-team.github.io/js-sdk-docs/en/start/example Documentation for the `ICurrencyField` interface in the Lark Base JS SDK, detailing methods for interacting with currency fields. This includes retrieving the field instance, getting and setting the currency code, and performing CRUD operations on currency values for specific records. ```APIDOC ICurrencyField: Description: Interface representing a currency field in a Bitable table. Methods: getCurrencyCode(): Promise Description: Retrieves the currency code of the field. Returns: Promise - The currency code (e.g., "USD", "EUR"). setCurrencyCode(currencyCode: string): Promise Description: Sets the currency code for the field. Parameters: currencyCode: string - The new currency code to set. Returns: Promise getValue(recordId: string): Promise Description: Retrieves the numeric value of the currency field for a specific record. Parameters: recordId: string - The ID of the record. Returns: Promise - The currency value. setValue(recordId: string, value: number): Promise Description: Sets the numeric value of the currency field for a specific record. Parameters: recordId: string - The ID of the record. value: number - The new numeric value to set. Returns: Promise ``` -------------------------------- ### Get Progress Field Cell Source: https://lark-base-team.github.io/js-sdk-docs/en/api/field/progress Gets the cell of the Progress Field for the specified record. ```TypeScript getCell: (recordOrId: IRecordType | string) => Promise; ```