Skip to content

Table instance ​

Get the TableInstance through a template ref and call scrollTo({ key, index, top }). The arguments follow the positioning approach of the Table underlying ProTable, and add horizontal position, alignment and explicit result feedback.

ts
import { ref } from 'vue'
import type { TableInstance } from '@vtable-guild/vtable-guild'

const table = ref<TableInstance>()
const found = await table.value?.scrollTo({ key: 'order-20', align: 'top' })
await table.value?.scrollTo({ top: 0, left: 0 })

Bind ref="table" to VTable; the normal body and the virtual body use the same interface. See TableScrollToOptions for the arguments.

It returns Promise<boolean>: true when the scrollable container and the target are found; false when the table is not mounted, the arguments are invalid or the target does not exist. For variable row heights the virtual list uses its existing measurement and correction mechanism; the Promise means the positioning has been submitted, and does not guarantee the final pixel position after images load asynchronously later.

Positioning covers the records that are loaded and visible on the current page. Rows on other pages, rows removed by filtering and rows inside a collapsed tree return false; the application switches pages, expands or loads first, then positions after the next render. It does not walk remote data automatically to find a record.

Lazy loading errors and retry ​

getTreeLoadError(key) returns the current load error or undefined; await retryTreeLoad(key) retries a node in an already loaded page and returns whether it succeeded, without changing the expanded keys. Clicking the error icon retries as well. Cached nodes that loaded successfully are not requested again.

Edit in Playground

API ​

After getting the TableInstance through a template ref, you can call the following methods.

Instance methods ​

MethodTypeDescription
scrollTo(options: TableScrollToOptions) => Promise<boolean>Scrolls to the given row or position; see options. Returns false when the target is not found, the table is not mounted or the arguments are invalid.
retryTreeLoad(key: Key) => Promise<boolean>Retries lazy loading for the node without changing its expanded state.
getTreeLoadError(key: Key) => Error | undefinedReads the lazy loading error of the row.

TableScrollToOptions ​

The arguments of scrollTo. Provide at least one of key, index, top and left.

FieldTypeDefaultDescription
keyKey-Stable row key; takes precedence over index and top. The number 0 and the empty string are supported.
indexnumber-Zero-based index among the visible rows of the current page; tree data counts the visible flattened rows after expansion.
topnumber-Vertical pixel position, effective when neither key nor index is given; clamped to the scrollable range when out of bounds.
leftnumber-Horizontal pixel position; clamped to the scrollable range when out of bounds.
align'top' | 'bottom' | 'auto''top'Alignment of the target row. auto does not scroll when the target row is already fully visible, and otherwise aligns to the nearest edge.
offsetnumber0Distance kept from the edge after aligning, in px.

Type Declarations ​

View type declarations
ts
export type { TableInstance, TableScrollToOptions } from '@vtable-guild/vtable-guild'