Base Module
Methods to retrieve information from the base
module.
const base = bitable.base;
const base = bitable.base;
getActiveTable
getActiveTable: () => Promise<ITable>;
getActiveTable: () => Promise<ITable>;
getActiveTable
is used to retrieve the currently active table.
const table = await base.getActiveTable();
const table = await base.getActiveTable();
getTable
getTable(idOrName: string): Promise<ITable>
getTable(idOrName: string): Promise<ITable>
Retrieves a table by its name or ID.
const table = await base.getTable(idOrName);
const table = await base.getTable(idOrName);
getTableById
getTableById(id: string): ITable[];
getTableById(id: string): ITable[];
Retrieves a table by its ID.
const tableById = await base.getTableById(id);
const tableById = await base.getTableById(id);
getTableByName
getTableByName(name: string): Promise<ITable>
getTableByName(name: string): Promise<ITable>
Retrieves a table by its name.
const table = await base.getTableByName(name);
const table = await base.getTableByName(name);
getTableList
getTableList: () => Promise<ITable[]>;
getTableList: () => Promise<ITable[]>;
Retrieves all tables in the base.
const tableList = await base.getTableList();
const tableList = await base.getTableList();
getSelection
Retrieves the current tableId and other information.
const { tableId, viewId } = await base.getSelection();
const { tableId, viewId } = await base.getSelection();
getTableMetaList
getTableMetaList(): Promise<TableMeta[]>
getTableMetaList(): Promise<TableMeta[]>
Retrieves the metadata of all tables in the base.
const tableMetaList = await base.getTableMetaList();
const tableMetaList = await base.getTableMetaList();
getPermission
getPermission(params: GetPermissionParams): Promise<boolean>;
getPermission(params: GetPermissionParams): Promise<boolean>;
Retrieves the permission for Base, Table, Field, Record, Cell, and other entities. Returns true
if the permission exists, false
otherwise.
The GetPermissionParams
type is defined as follows:
type GetPermissionParams = BasePermissionParams | TablePermissionParams | RecordPermissionParams | FieldPermissionParams | CellPermissionParams;
interface BasePermissionParams {
entity: PermissionEntity.Base;
type: BaseOperation;
}
interface TablePermissionParams {
entity: PermissionEntity.Table;
param: {
tableId?: string;
};
type: TableOperation;
}
interface RecordPermissionParams {
entity: PermissionEntity.Record;
param: {
tableId: string;
recordId?: string;
};
type: RecordOperation;
}
interface FieldPermissionParams {
entity: PermissionEntity.Field;
param: {
tableId: string;
fieldId?: string;
};
type: FieldOperation;
}
interface CellPermissionParams {
entity: PermissionEntity.Cell;
param: {
tableId: string;
recordId?: string;
fieldId?: string;
};
type: CellOperation;
}
type GetPermissionParams = BasePermissionParams | TablePermissionParams | RecordPermissionParams | FieldPermissionParams | CellPermissionParams;
interface BasePermissionParams {
entity: PermissionEntity.Base;
type: BaseOperation;
}
interface TablePermissionParams {
entity: PermissionEntity.Table;
param: {
tableId?: string;
};
type: TableOperation;
}
interface RecordPermissionParams {
entity: PermissionEntity.Record;
param: {
tableId: string;
recordId?: string;
};
type: RecordOperation;
}
interface FieldPermissionParams {
entity: PermissionEntity.Field;
param: {
tableId: string;
fieldId?: string;
};
type: FieldOperation;
}
interface CellPermissionParams {
entity: PermissionEntity.Cell;
param: {
tableId: string;
recordId?: string;
fieldId?: string;
};
type: CellOperation;
}
When using this method, you need to pass in the corresponding configuration to query the corresponding permission. Below is an example of querying field permissions:
const fieldInfo: FieldPermissionParams = {
entity: PermissionEntity.Field,
param: {
tableId,
fieldId,
},
type: OperationType.Editable,
}
const hasPermission = await base.getPermission(params);
const fieldInfo: FieldPermissionParams = {
entity: PermissionEntity.Field,
param: {
tableId,
fieldId,
},
type: OperationType.Editable,
}
const hasPermission = await base.getPermission(params);
In this example, we pass in the entity
to specify that we want to query field permissions, param
is used to specify the field we want to check, and type
is the type of permission we want to check (in this case, editable permission).
WARNING
Note: In advanced permission scenarios, checking editable
permission for the Table entity will return false. To check permissions for specific rows, columns, or views, use Record
, Field
, or View
entity types instead.
isEditable
isEditable(): Promise<boolean>;
isEditable(): Promise<boolean>;
Checks if the current user has the permission to edit.
const isEditable = await base.isEditable();
const isEditable = await base.isEditable();
batchUploadFile
batchUploadFile(file: File[] | FileList): Promise<string[]>;
batchUploadFile(file: File[] | FileList): Promise<string[]>;
Uploads multiple files and returns a list of fileTokens corresponding to each file.
WARNING
Note: Due to internal mechanism constraints, concurrent calls to batchUploadFile
are prohibited as they may cause unexpected errors. It is recommended to use sequential calls or ensure the previous call completes before initiating a new request.
onTableDelete
onTableDelete(callback: () => void): () => void;
onTableDelete(callback: () => void): () => void;
Listens for table add events.
onTableAdd
onTableAdd(callback: () => void): () => void;
onTableAdd(callback: () => void): () => void;
Listens for table delete events.
onSelectionChange
onSelectionChange(callback: () => void): () => void;
onSelectionChange(callback: () => void): () => void;
Listens for selection change events.
onPermissionChange
onPermissionChange(callback: () => void): () => void;
onPermissionChange(callback: () => void): () => void;
Listens for permission change events.