Remote dictionaries
createTableDictionary creates an explicitly shared dictionary instance, and useTableDictionary connects it to Vue state. One result can feed the cell valueEnum, the header filters and the Select controls your project already has. Dictionary requests are independent of the row data requests of useTableRequest, and no request or watcher is created per cell.
Defining and connecting
const dictionary = createTableDictionary<{ region: string }>({
key: 'owners',
request: async (params, { keyword, signal }) => {
const response = await fetch(
`/api/owners?region=${encodeURIComponent(params.region ?? '')}&q=${encodeURIComponent(keyword)}`,
{ signal },
)
if (!response.ok) throw new Error('Failed to load owners')
// Returns { options: [{ value: 1, label: 'Chen Jia' }], complete: false }
return response.json()
},
})
const owners = useTableDictionary({
dictionary,
params: () => ({ region: region.value }),
selectedOptions: () => selectedOwners.value,
debounceTime: 200,
})
// Read them inside computed columns; options can be passed straight to a-select / el-select.
const columns = computed(() => [
{
dataIndex: 'ownerId',
valueEnum: owners.valueEnum.value,
filters: owners.filters.value,
},
])Each element of options is { value, label, status?, disabled? }; label is a string, and value can be a string, a finite number or a boolean. The valueEnum provided as a Map preserves the difference between 1, '1' and false; unknown values still fall back to the table's raw value. Complex custom labels are handled by the host control's slots or by a cell renderer.
Complete dictionaries and search results
The request must return complete. Only a successful result with complete: true and an empty keyword produces filters; in every other case it is []. Do not use filters: true with remote search results: the known labels do not represent the complete filter set. To show both a complete header filter and remote search, use two composables that share the same dictionary, as in the example.
options holds the candidate options of the current request and never mixes in selected options; valueEnum keeps the labels known under the current dependency params and merges in selectedOptions, and a complete result replaces the labels accumulated by earlier searches. Currently loaded labels take precedence over stale labels provided from outside. If the host Select needs the selected options to appear in the options array, the application merges the currently selected items with options.
A change to params cancels the current subscription, clears the keyword / old candidate options / known labels, and then reloads; it does not modify the application's selected values. In cascading scenarios the application can clear the downstream selection explicitly; pass selectedOptions when you want the old selection to keep displaying.
Sharing, caching and cancellation
- A single dictionary instance merges in-flight requests by dependency params and keyword; successful results are cached for 5 minutes by default, and at most 50 entries are kept.
keyis a stable application identifier; two independent instances with the same name are still isolated. Sharing relies on passing the instance explicitly rather than on a process-level global registry; in SSR, create the instance inside the setup/provider of each request.- Each subscription has its own signal; one control cancelling or unmounting does not cancel other subscriptions, and the underlying request is aborted only when the last subscription leaves. A stale response is never written into newer state, even if it ignores the signal.
reload()skips the completed cache immediately but still reuses an identical in-flight request; errors are not cached.dictionary.invalidate()forgets all caches without actively refreshing the controls; existing subscriptions may complete, but their results do not re-enter the cache.- A refresh updates the state of the current composable; other completed subscriptions are not rewritten by a broadcast. When they need refreshing, call
reload()on the relevant subscriptions; requests made at the same moment are merged.
API
The value types of a host Select follow its own protocol. For example, the Ant Design Vue Select does not accept boolean values; when connecting a boolean dictionary, the application should use a reversible control value mapping and restore the original type on submit. Do not merge false and 'false', or 1 and '1', into the same dictionary key.
createTableDictionary options
createTableDictionary(options) creates a dictionary instance.
| Option | Type | Default | Description |
|---|---|---|---|
key | string | Required | Stable application identifier. Two instances with the same key are still isolated from each other. |
request | TableDictionaryRequest<TParams> | Required | (params, { signal, keyword }) => Promise<{ options, complete }>; the result must state whether it is the complete dictionary. |
cacheTime | number | 300000 | Cache time in milliseconds for successful results; 0 turns off result caching. |
maxEntries | number | 50 | Maximum number of cache entries kept, at least 1; entries with subscribers are never evicted. |
Dictionary instance
| Property or method | Type | Description |
|---|---|---|
key | string | Application identifier passed on creation. |
load | (params: Partial<TParams>, context: TableDictionaryContext & { force?: boolean }) => Promise<TableDictionaryResult> | For code outside components. Returns an independent snapshot of the result and rejects on failure or cancellation; force skips the completed cache. |
invalidate | () => void | Clears the instance cache without refreshing existing subscriptions. |
useTableDictionary options
| Option | Type | Default | Description |
|---|---|---|---|
dictionary | TableDictionary<TParams> | Required | Shared dictionary instance. |
params | MaybeRefOrGetter<Partial<TParams>> | - | Dependency params. A change clears the keyword and options and reloads; the application's selected value is not modified. |
defaultKeyword | string | '' | Initial search keyword. |
selectedOptions | MaybeRefOrGetter<readonly TableDictionaryOption[]> | - | Labels of the selected options, used to display selections missing from the latest search results. |
manualRequest | boolean | false | Skip the first request; later changes of the dependency params still load. |
debounceTime | number | 0 | Debounce in milliseconds for search. |
onError | (error: Error) => void | - | Called when a request fails. |
useTableDictionary return value
| Property or method | Type | Description |
|---|---|---|
options | ComputedRef<readonly TableDictionaryOption[]> | Options from the current request; selected options are not mixed in. |
valueEnum | ComputedRef<ReadonlyMap<ColumnValue, ColumnValueEnumItem>> | Labels known under the current dependency params, merged with selectedOptions; usable directly as a column's valueEnum. |
filters | ComputedRef<ColumnFilterItem[]> | Header filter items; populated only for a complete dictionary with an empty keyword, [] otherwise. |
complete | Readonly<Ref<boolean>> | Whether the current result is the complete dictionary. |
loading | Readonly<Ref<boolean>> | A request is in flight. |
error | Readonly<Ref<Error | null>> | Error from the last request. |
keyword | Readonly<Ref<string>> | Current search keyword. |
search | (keyword: string) => Promise<boolean> | Updates the keyword and sends a debounced request. Returns true on success, false on failure, cancellation or unmount. |
reload | () => Promise<boolean> | Reloads the current query immediately, skipping the completed cache. |
cancel | () => void | Cancels this subscription; the current options and labels are kept. |
TableDictionaryOption
The elements of options and selectedOptions.
| Field | Type | Default | Description |
|---|---|---|---|
value | string | number | boolean | Required | Option value; numbers must be finite. |
label | string | Required | Display text. |
status | 'success' | 'warning' | 'error' | 'processing' | 'default' | - | Status color, the same as status in valueEnum. |
disabled | boolean | - | Whether the option is disabled. |
The composable's search/reload return true on success and false on failure, cancellation or unmount; a failure also updates error and calls onError. If onError itself throws, that exception is stored in error and the returned Promise still settles normally. manualRequest skips only the first request; later dependency param changes still load. Create it inside setup or an effectScope so that it is cleaned up automatically.
The public types are TableDictionaryOption, TableDictionaryResult, TableDictionaryContext, TableDictionaryRequest, CreateTableDictionaryOptions, TableDictionary, UseTableDictionaryOptions, UseTableDictionaryReturn.
VTable Column fields
| Field | Type | Default | Description |
|---|---|---|---|
valueEnum | ColumnValueEnum | - | Maps raw values to display text and status. Accepts an object or a Map. |
valueType | string | - | Specifies a built-in field render type or a registered custom type. |
fieldProps | TableFieldProps | ((context: CustomRenderContext<TRecord>) => TableFieldProps) | - | Configures the field renderer. Accepts an object or a function that returns the configuration from the cell context. |
Theming
A dictionary provides option and label data. When dictionary labels are displayed in the table as enum statuses, they use the table slots and CSS variables below; the appearance of the query area and of editing controls is determined by the corresponding components.
ui slots
| Slot | Description |
|---|---|
cellStatus | valueEnum status marker, colored by data-status. |
Preset defaults
createVTableGuild({
theme: {
table: {
slots: {
cellStatus: "inline-flex items-center gap-1 before:content-[''] before:size-1.5 before:rounded-full before:bg-[color:var(--color-muted)] [&[data-status=success]]:before:bg-[color:var(--vtg-cell-success)] [&[data-status=warning]]:before:bg-[color:var(--vtg-cell-warning)] [&[data-status=error]]:before:bg-[color:var(--vtg-cell-error)] [&[data-status=processing]]:before:bg-[color:var(--color-primary)]",
},
},
},
})createVTableGuild({
themePreset: 'element-plus',
theme: {
table: {
slots: {
cellStatus: "inline-flex items-center gap-1 before:content-[''] before:size-1.5 before:rounded-full before:bg-[color:var(--color-muted)] [&[data-status=success]]:before:bg-[color:var(--vtg-cell-success)] [&[data-status=warning]]:before:bg-[color:var(--vtg-cell-warning)] [&[data-status=error]]:before:bg-[color:var(--vtg-cell-error)] [&[data-status=processing]]:before:bg-[color:var(--color-primary)]",
},
},
},
})CSS variables
| Variable | Purpose | antdv | element-plus |
|---|---|---|---|
--vtg-cell-success | Field success status color | #52c41a | #67c23a |
--vtg-cell-warning | Field warning status color | #faad14 | #e6a23c |
--vtg-cell-error | Field error status color; also used for query and editing validation text | #ff4d4f | #f56c6c |
Type Declarations
View type declarations
export { createTableDictionary, useTableDictionary } from '@vtable-guild/vtable-guild'
export type {
TableDictionaryOption,
TableDictionaryBinding,
TableDictionaryResult,
TableDictionaryContext,
TableDictionaryRequest,
TableDictionary,
CreateTableDictionaryOptions,
UseTableDictionaryOptions,
UseTableDictionaryReturn,
} from '@vtable-guild/vtable-guild'