API 参考

FBaseTableView

本 API 页面目前提供英文正文。代码签名与标识符不随界面语言变化。

Facade API object bound to a Base view.

A view stores table projection settings such as filter, sort, group, field visibility, and view-specific config. The facade writes those settings through commands so projections, events, and collaboration invalidations stay in sync.

Access

Access through:

Example

Configure a grid projection

TypeScript
const fBase = univerAPI.getActiveBase()const fBaseTable = fBase.getTableById('table-1')const grid = fBaseTable.createView('Main Grid', univerAPI.Enum.BaseViewType.Grid)grid.updateConfig({ frozenFieldCount: 1 })grid.setFilter({  conjunction: univerAPI.Enum.BaseFilterConjunction.AND,  conditions: [    {      fieldId: 'status',      operator: univerAPI.Enum.BaseFilterOperator.IS,      operand: 'done',    },  ],})grid.setSort([  {    fieldId: 'progress',    direction: univerAPI.Enum.BaseSortDirection.DESC,  },])grid.setFieldVisible('internalNotes', false)const projection = grid.getProjection()console.log(projection)

Setup

Register @univerjs-pro/bases or a preset that includes it. In plugin mode, import @univerjs-pro/bases/facade. Additional methods below require their listed plugin packages. See Facade setup.

@univerjs-pro/bases

FBaseTableView.addConditionalColorRule

Append one conditional coloring rule at the lowest priority.

Use setConditionalColorRules when inserting at a specific priority or replacing an existing rule. Duplicate ids and invalid rule values throw before the Base is mutated.

TypeScript
addConditionalColorRule(rule: IBaseConditionalColorRule): boolean

Parameters

  • rule — Required. Rule to append after all existing rules.

Returns

true when the update command succeeds; otherwise false.

Examples

Add a low-priority warning rule

TypeScript
const base = univerAPI.getActiveBase()if (!base) throw new Error('Open a Base before running this example.')const table = base.insertTable(`Conditional color add ${Date.now()}`, {  primaryFieldName: 'Risk item',})const level = table.addField('Risk level', univerAPI.Enum.BaseFieldType.Number)const view = table.getViewByName('Grid')if (!view) throw new Error('The default Grid view was not created.')const success = view.addConditionalColorRule({  id: 'medium-risk',  color: '#fff7df',  target: univerAPI.Enum.BaseConditionalColorTarget.CELL,  fieldId: level.getId(),  operator: univerAPI.Enum.BaseConditionalColorOperator.GREATER_THAN,  operand: 50,})console.log({ success, rules: view.getConditionalColorRules() })

Types: IBaseConditionalColorRule

Package: @univerjs-pro/bases · Type definitions

FBaseTableView.clearConditionalColorRules

Clear every conditional coloring rule from this view.

TypeScript
clearConditionalColorRules(): boolean

Returns

true when rules existed and the clear command succeeds; otherwise false.

Examples

Clear conditional coloring without changing filters, sorts, or other view config

TypeScript
const base = univerAPI.getActiveBase()if (!base) throw new Error('Open a Base before running this example.')const table = base.insertTable(`Conditional color clear ${Date.now()}`, {  primaryFieldName: 'Task',})const title = table.getPrimaryField()const view = table.getViewByName('Grid')if (!view) throw new Error('The default Grid view was not created.')view.addConditionalColorRule({  id: 'temporary-rule',  color: '#eef3ff',  target: univerAPI.Enum.BaseConditionalColorTarget.CELL,  fieldId: title.getId(),  operator: univerAPI.Enum.BaseConditionalColorOperator.IS_NOT_EMPTY,})const cleared = view.clearConditionalColorRules()console.log({ cleared, rules: view.getConditionalColorRules() })

Package: @univerjs-pro/bases · Type definitions

FBaseTableView.delete

Delete this view.

TypeScript
delete(): boolean

Returns

True if the view was deleted, false if the view was already deleted.

Examples

TypeScript
const fBase = univerAPI.getActiveBase()const fBaseTable = fBase.getTableById('table-1')const view = fBaseTable.getViewByName('Grid')const success = view.delete()console.log(success ? 'View deleted' : 'Delete view failed')

Package: @univerjs-pro/bases · Type definitions

FBaseTableView.deleteConditionalColorRule

Delete one conditional coloring rule by its stable id.

Deleting the last rule clears the persisted conditional coloring config. A missing id is a no-op and returns false.

TypeScript
deleteConditionalColorRule(ruleId: string): boolean

Parameters

  • ruleId — Required. Id of the rule to delete.

Returns

true when the rule existed and the update command succeeds; otherwise false.

Examples

Delete a rule and verify the persisted result

TypeScript
const base = univerAPI.getActiveBase()if (!base) throw new Error('Open a Base before running this example.')const table = base.insertTable(`Conditional color delete ${Date.now()}`, {  primaryFieldName: 'Task',})const title = table.getPrimaryField()const view = table.getViewByName('Grid')if (!view) throw new Error('The default Grid view was not created.')view.addConditionalColorRule({  id: 'medium-risk',  color: '#fff7df',  target: univerAPI.Enum.BaseConditionalColorTarget.CELL,  fieldId: title.getId(),  operator: univerAPI.Enum.BaseConditionalColorOperator.CONTAINS,  operand: 'delay',})const deleted = view.deleteConditionalColorRule('medium-risk')console.log({ deleted, rules: view.getConditionalColorRules() })

Package: @univerjs-pro/bases · Type definitions

FBaseTableView.getConditionalColorRules

Get this view's conditional coloring rules in priority order.

Rules at the beginning of the array have higher priority. The returned array is a deep copy, so changing it does not mutate the Base. Call setConditionalColorRules to persist edits or reorder rules.

TypeScript
getConditionalColorRules(): IBaseConditionalColorRule[]

Returns

A copy of the persisted rules. Returns [] when no rules are configured.

Examples

Read rules created by either the UI or the Facade

TypeScript
const base = univerAPI.getActiveBase()if (!base) throw new Error('Open a Base before running this example.')const table = base.insertTable(`Conditional color read ${Date.now()}`, {  primaryFieldName: 'Task',})const title = table.getPrimaryField()const view = table.getViewByName('Grid')if (!view) throw new Error('The default Grid view was not created.')view.setConditionalColorRules([  {    id: 'blocked-task',    color: '#fde9e9',    target: univerAPI.Enum.BaseConditionalColorTarget.CELL,    fieldId: title.getId(),    operator: univerAPI.Enum.BaseConditionalColorOperator.CONTAINS,    operand: 'blocked',  },])const rules = view.getConditionalColorRules()console.log(rules.map((rule, priority) => ({ priority, ...rule })))

Types: IBaseConditionalColorRule

Package: @univerjs-pro/bases · Type definitions

FBaseTableView.getConfig

Get the view-specific config.

TypeScript
getConfig(): ViewSpecificConfig

Returns

The view-specific config.

Examples

TypeScript
const fBase = univerAPI.getActiveBase()const fBaseTable = fBase.getTableById('table-1')const view = fBaseTable.getViewByName('Grid')const config = view.getConfig()console.log(config)

Types: ViewSpecificConfig

Package: @univerjs-pro/bases · Type definitions

FBaseTableView.getFieldSettings

Get settings for a field in this view.

TypeScript
getFieldSettings(fieldId: string): IViewFieldSetting

Parameters

  • fieldId — Required. The field id.

Returns

The field settings, or an empty object if no settings are set.

Examples

TypeScript
const fBase = univerAPI.getActiveBase()const fBaseTable = fBase.getTableById('table-1')const view = fBaseTable.getViewByName('Grid')const settings = view.getFieldSettings('status')console.log(settings)

Types: IViewFieldSetting

Package: @univerjs-pro/bases · Type definitions

FBaseTableView.getFilter

Get the view filter.

TypeScript
getFilter(): IFilterConfig | null

Returns

The view filter, or null if no filter is set.

Examples

TypeScript
const fBase = univerAPI.getActiveBase()const fBaseTable = fBase.getTableById('table-1')const view = fBaseTable.getViewByName('Grid')console.log(view.getFilter())

Types: IFilterConfig

Package: @univerjs-pro/bases · Type definitions

FBaseTableView.getGroup

Get the view group rules.

TypeScript
getGroup(): IGroupConfig[]

Returns

The group rules.

Examples

TypeScript
const fBase = univerAPI.getActiveBase()const fBaseTable = fBase.getTableById('table-1')const view = fBaseTable.getViewByName('Grid')console.log(view.getGroup())

Types: IGroupConfig

Package: @univerjs-pro/bases · Type definitions

FBaseTableView.getId

Get the view id.

TypeScript
getId(): string

Returns

The view id.

Examples

TypeScript
const fBase = univerAPI.getActiveBase()const fBaseTable = fBase.getTableById('table-1')const views = fBaseTable.getViews()console.log(views[0]?.getId())

Package: @univerjs-pro/bases · Type definitions

FBaseTableView.getName

Get the view name.

TypeScript
getName(): string

Returns

The view name.

Examples

TypeScript
const fBase = univerAPI.getActiveBase()const fBaseTable = fBase.getTableById('table-1')const views = fBaseTable.getViews()console.log(views[0]?.getName())

Package: @univerjs-pro/bases · Type definitions

FBaseTableView.getPermission

Returns the View object permission facade.

TypeScript
getPermission(): FBaseObjectPermission

Returns

Permission facade combining the Base, Table, and View Edit points.

Examples

TypeScript
const table = univerAPI.getActiveBase()?.getTables()[0]const view = table?.getViews()[0]if (!view) throw new Error('View not found.')await view.getPermission().setReadOnly()

Types: FBaseObjectPermission

Package: @univerjs-pro/bases · Type definitions

FBaseTableView.getProjection

Get the projected rows and fields for this view.

The projection is computed from the current table snapshot plus this view's filter, sort, group, field order, visibility, and type-specific config.

TypeScript
getProjection(): BaseViewProjection

Returns

The projected rows and fields.

Examples

TypeScript
const fBase = univerAPI.getActiveBase()const fBaseTable = fBase.getTableById('table-1')const view = fBaseTable.getViewByName('Grid')console.log(view.getProjection())

Types: BaseViewProjection

Package: @univerjs-pro/bases · Type definitions

FBaseTableView.getSort

Get the view sort rules.

TypeScript
getSort(): ISortConfig[]

Returns

The sort rules.

Examples

TypeScript
const fBase = univerAPI.getActiveBase()const fBaseTable = fBase.getTableById('table-1')const view = fBaseTable.getViewByName('Grid')console.log(view.getSort())

Types: ISortConfig

Package: @univerjs-pro/bases · Type definitions

FBaseTableView.getType

Get the view type.

TypeScript
getType(): BaseViewType

Returns

The view type.

Examples

TypeScript
const fBase = univerAPI.getActiveBase()const fBaseTable = fBase.getTableById('table-1')const views = fBaseTable.getViews()console.log(views[0]?.getType())

Types: BaseViewType

Package: @univerjs-pro/bases · Type definitions

FBaseTableView.getView

Get the view snapshot.

TypeScript
getView(): IViewSnapshot

Returns

The view snapshot.

Examples

TypeScript
const fBase = univerAPI.getActiveBase()const fBaseTable = fBase.getTableById('table-1')const views = fBaseTable.getViews()console.log(views[0]?.getView())

Types: IViewSnapshot

Package: @univerjs-pro/bases · Type definitions

FBaseTableView.getVisibleFields

Get visible fields in this view.

TypeScript
getVisibleFields(): FBaseTableField[]

Returns

An array of visible fields in this view.

Examples

TypeScript
const fBase = univerAPI.getActiveBase()const fBaseTable = fBase.getTableById('table-1')const view = fBaseTable.getViewByName('Grid')console.log(view.getVisibleFields())

Types: FBaseTableField

Package: @univerjs-pro/bases · Type definitions

FBaseTableView.move

Move this view relative to another view.

TypeScript
move(target: { beforeViewId?: string; afterViewId?: string; }): boolean

Parameters

  • target — Required. Target position descriptor. Pass exactly one of beforeViewId or afterViewId.

Returns

True if the view was moved, false if the view was already in the target position.

Examples

TypeScript
const fBase = univerAPI.getActiveBase()const fBaseTable = fBase.getTableById('table-1')const view = fBaseTable.getViewByName('Grid')const success = view.move({ beforeViewId: 'calendar' })console.log(success ? 'View moved' : 'Move view failed')

Package: @univerjs-pro/bases · Type definitions

FBaseTableView.moveField

Move a field in this view.

TypeScript
moveField(fieldId: string, target: { beforeFieldId?: string; afterFieldId?: string; }): boolean

Parameters

  • fieldId — Required. The field id.
  • target — Required. Target position descriptor. Pass exactly one of beforeFieldId or afterFieldId.

Returns

True if the field was moved, false if the field was already in the target position.

Examples

TypeScript
const fBase = univerAPI.getActiveBase()const fBaseTable = fBase.getTableById('table-1')const view = fBaseTable.getViewByName('Grid')const success = view.moveField('status', { afterFieldId: 'title' })console.log(success ? 'Field moved' : 'Move field failed')

Package: @univerjs-pro/bases · Type definitions

FBaseTableView.setConditionalColorRules

Replace all conditional coloring rules for this view.

The array order is the rule priority: index 0 is evaluated first. Passing [] clears conditional coloring. Every rule id must be unique, and every fieldId must reference a public field in this table. Invalid targets, field/operator combinations, date modes, CSS colors, ids, or fields throw an actionable error before any mutation is executed. For a COLUMN target, the field's entire column is painted unconditionally; operator, operand, and dateMode are retained but ignored.

Prefer this typed method and univerAPI.Enum.BaseConditional* values to writing getConfig().conditionalColoring through updateConfig; the command validates the complete replacement before persisting it.

TypeScript
setConditionalColorRules(rules: IBaseConditionalColorRule[]): boolean

Parameters

  • rules — Required. Complete replacement rules in descending priority order.

Returns

true when the update command succeeds; otherwise false.

Examples

Create a runnable risk table and color high-risk rows

TypeScript
const base = univerAPI.getActiveBase()if (!base) throw new Error('Open a Base before running this example.')const table = base.insertTable(`Risk tracker ${Date.now()}`, {  primaryFieldName: 'Risk item',})const level = table.addField('Risk level', univerAPI.Enum.BaseFieldType.Number)table.addRecords([  { values: { [table.getPrimaryFieldId()]: 'Stock shortage', [level.getId()]: 90 } },  { values: { [table.getPrimaryFieldId()]: 'Delivery delay', [level.getId()]: 60 } },])const view = table.getViewByName('Grid')if (!view) throw new Error('The default Grid view was not created.')const success = view.setConditionalColorRules([  {    id: 'high-risk',    color: '#fde9e9',    target: univerAPI.Enum.BaseConditionalColorTarget.ROW,    fieldId: level.getId(),    operator: univerAPI.Enum.BaseConditionalColorOperator.GREATER_THAN,    operand: 80,  },])console.log({ success, rules: view.getConditionalColorRules() })

Types: IBaseConditionalColorRule

Package: @univerjs-pro/bases · Type definitions

FBaseTableView.setFieldVisible

Show or hide a field in this view.

This changes only the view-local field setting. The table field remains present and other views are not affected.

TypeScript
setFieldVisible(fieldId: string, visible: boolean): boolean

Parameters

  • fieldId — Required. The field id.
  • visible — Required. True to show the field, false to hide it.

Returns

True if the visibility was changed, false if the visibility was unchanged.

Examples

TypeScript
const fBase = univerAPI.getActiveBase()const fBaseTable = fBase.getTableById('table-1')const view = fBaseTable.getViewByName('Grid')const success = view.setFieldVisible('progress', false)console.log(success ? 'Field visibility changed' : 'Set field visibility failed')

Package: @univerjs-pro/bases · Type definitions

FBaseTableView.setFieldWidth

Set a field width in this view.

TypeScript
setFieldWidth(fieldId: string, width: number): boolean

Parameters

  • fieldId — Required. The field id.
  • width — Required. The field width in pixels.

Returns

True if the width was set, false if the width was unchanged.

Examples

TypeScript
const fBase = univerAPI.getActiveBase()const fBaseTable = fBase.getTableById('table-1')const view = fBaseTable.getViewByName('Grid')const success = view.setFieldWidth('title', 240)console.log(success ? 'Field width set' : 'Set field width failed')

Package: @univerjs-pro/bases · Type definitions

FBaseTableView.setFilter

Set the view filter.

TypeScript
setFilter(filter: IFilterConfig | null): boolean

Parameters

  • filter — Required. The filter to set, or null to clear the filter.

Returns

True if the filter was set, false if the filter was unchanged.

Examples

TypeScript
const fBase = univerAPI.getActiveBase()const fBaseTable = fBase.getTableById('table-1')const fields = fBaseTable.getFields()const conditions = fields.map((field) => {  if (field.getId() === 'status') {    return {      fieldId: field.getId(),      operator: univerAPI.Enum.BaseFilterOperator.IS,      operand: 'done',    }  }  return {    fieldId: field.getId(),    operator: univerAPI.Enum.BaseFilterOperator.IS_NOT,    operand: 'done',  }})const view = fBaseTable.getViewByName('Grid')const success = view.setFilter({  conjunction: univerAPI.Enum.BaseFilterConjunction.AND,  conditions,})console.log(success ? 'Filter set' : 'Set filter failed')

Types: IFilterConfig

Package: @univerjs-pro/bases · Type definitions

FBaseTableView.setGroup

Set the view group rules.

Group rules are view projection metadata. They do not mutate record values or field definitions.

TypeScript
setGroup(group: IGroupConfig[]): boolean

Parameters

  • group — Required. Group rules. Pass [] to clear grouping.

Examples

TypeScript
const fBase = univerAPI.getActiveBase()const fBaseTable = fBase.getTableById('table-1')const view = fBaseTable.getViewByName('Grid')const success = view.setGroup([  {    fieldId: 'status',    direction: univerAPI.Enum.BaseSortDirection.ASC,  },])console.log(success ? 'Group set' : 'Set group failed')

Types: IGroupConfig

Package: @univerjs-pro/bases · Type definitions

FBaseTableView.setName

Rename this view.

TypeScript
setName(name: string): boolean

Parameters

  • name — Required. The new view name.

Returns

True if the rename succeeded, false if the name was unchanged.

Examples

TypeScript
const fBase = univerAPI.getActiveBase()const fBaseTable = fBase.getTableById('table-1')const view = fBaseTable.getViewByName('Grid')if (view) {  const success = view.setName('Release view')  console.log(success ? 'View renamed' : 'Rename failed')}

Package: @univerjs-pro/bases · Type definitions

FBaseTableView.setSort

Set the view sort rules.

TypeScript
setSort(sort: ISortConfig[]): boolean

Parameters

  • sort — Required. The sort rules.

Returns

True if the sort was set, false if the sort was unchanged.

Examples

TypeScript
const fBase = univerAPI.getActiveBase()const fBaseTable = fBase.getTableById('table-1')const view = fBaseTable.getViewByName('Grid')const success = view.setSort([  {    fieldId: 'priority',    direction: univerAPI.Enum.BaseSortDirection.ASC,  },])console.log(success ? 'Sort set' : 'Set sort failed')

Types: ISortConfig

Package: @univerjs-pro/bases · Type definitions

FBaseTableView.updateConfig

Update the view-specific config.

TypeScript
updateConfig(patch: Partial<ViewSpecificConfig>): boolean

Parameters

  • patch — Required. The config fields to update.

Returns

True if the update succeeded, false if the config was unchanged.

Examples

TypeScript
const fBase = univerAPI.getActiveBase()const fBaseTable = fBase.getTableById('table-1')const view = fBaseTable.getViewByName('Grid')const gridConfig = view.getConfig() as IGridViewConfiggridConfig.frozenFieldCount = 2const success = view.updateConfig(gridConfig)console.log(success ? 'Config updated' : 'Update failed')

Types: Partial · ViewSpecificConfig

Package: @univerjs-pro/bases · Type definitions

你觉得这篇文档如何?

© 2026 DreamNum Co., Ltd.