FBaseTableView
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
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.
addConditionalColorRule(rule: IBaseConditionalColorRule): booleanParameters
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
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.
clearConditionalColorRules(): booleanReturns
true when rules existed and the clear command succeeds; otherwise false.
Examples
Clear conditional coloring without changing filters, sorts, or other view config
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.
delete(): booleanReturns
True if the view was deleted, false if the view was already deleted.
Examples
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.
deleteConditionalColorRule(ruleId: string): booleanParameters
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
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.
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
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.
getConfig(): ViewSpecificConfigReturns
The view-specific config.
Examples
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.
getFieldSettings(fieldId: string): IViewFieldSettingParameters
fieldId— Required. The field id.
Returns
The field settings, or an empty object if no settings are set.
Examples
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.
getFilter(): IFilterConfig | nullReturns
The view filter, or null if no filter is set.
Examples
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.
getGroup(): IGroupConfig[]Returns
The group rules.
Examples
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.
getId(): stringReturns
The view id.
Examples
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.
getName(): stringReturns
The view name.
Examples
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.
getPermission(): FBaseObjectPermissionReturns
Permission facade combining the Base, Table, and View Edit points.
Examples
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.
getProjection(): BaseViewProjectionReturns
The projected rows and fields.
Examples
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.
getSort(): ISortConfig[]Returns
The sort rules.
Examples
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.
getType(): BaseViewTypeReturns
The view type.
Examples
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.
getView(): IViewSnapshotReturns
The view snapshot.
Examples
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.
getVisibleFields(): FBaseTableField[]Returns
An array of visible fields in this view.
Examples
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.
move(target: { beforeViewId?: string; afterViewId?: string; }): booleanParameters
target— Required. Target position descriptor. Pass exactly one ofbeforeViewIdorafterViewId.
Returns
True if the view was moved, false if the view was already in the target position.
Examples
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.
moveField(fieldId: string, target: { beforeFieldId?: string; afterFieldId?: string; }): booleanParameters
fieldId— Required. The field id.target— Required. Target position descriptor. Pass exactly one ofbeforeFieldIdorafterFieldId.
Returns
True if the field was moved, false if the field was already in the target position.
Examples
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.
setConditionalColorRules(rules: IBaseConditionalColorRule[]): booleanParameters
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
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.
setFieldVisible(fieldId: string, visible: boolean): booleanParameters
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
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.
setFieldWidth(fieldId: string, width: number): booleanParameters
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
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.
setFilter(filter: IFilterConfig | null): booleanParameters
filter— Required. The filter to set, ornullto clear the filter.
Returns
True if the filter was set, false if the filter was unchanged.
Examples
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.
setGroup(group: IGroupConfig[]): booleanParameters
group— Required. Group rules. Pass[]to clear grouping.
Examples
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.
setName(name: string): booleanParameters
name— Required. The new view name.
Returns
True if the rename succeeded, false if the name was unchanged.
Examples
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.
setSort(sort: ISortConfig[]): booleanParameters
sort— Required. The sort rules.
Returns
True if the sort was set, false if the sort was unchanged.
Examples
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.
updateConfig(patch: Partial<ViewSpecificConfig>): booleanParameters
patch— Required. The config fields to update.
Returns
True if the update succeeded, false if the config was unchanged.
Examples
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
你觉得这篇文档如何?