Skip to main content

ProTable

A page-level table abstraction with built-in query, pagination, row selection, column settings, and operation columns.

VEF-specific component. Moved from @vef-framework-react/starter to @vef-framework-react/components in v2.1.6.

When to Use

  • Any data list page that needs query + pagination + row actions.
  • Tables that need column visibility control or virtual scrolling.

Basic Usage

import { ProTable } from '@vef-framework-react/components';
import type { TableColumn } from '@vef-framework-react/components';

interface User {
id: number;
name: string;
status: string;
}

const columns: TableColumn<User>[] = [
{ title: 'Name', dataIndex: 'name' },
{ title: 'Status', dataIndex: 'status' },
];

export default function UserTable() {
return (
<ProTable<User, UserSearchParams>
columns={columns}
rowKey="id"
queryFn={findUserPage}
queryParams={searchParams}
operationColumn={{
width: 120,
render: (row) => (
<OperationButton requiredPermissions="user:edit" onClick={() => openEdit(row)}>
Edit
</OperationButton>
)
}}
/>
);
}

Non-Paginated Mode

<ProTable<User, UserSearchParams>
isPaginated={false}
columns={columns}
rowKey="id"
queryFn={findUserList}
/>

With Row Selection

<ProTable
columns={columns}
rowKey="id"
queryFn={findUserPage}
rowSelection={true}
onSelectedRowKeysChange={(keys, rows) => setSelected(rows)}
/>

Imperative Ref

import { useRef } from 'react';
import type { ProTableRef } from '@vef-framework-react/components';

const tableRef = useRef<ProTableRef>(null);

// Manually refetch
tableRef.current?.refetch();

<ProTable ref={tableRef} ... />

API

PropTypeDefaultDescription
columnsTableColumn<TRow>[]Column definitions
rowKeyDeepKeys<TRow> | (row) => KeyRow key extractor
queryFnQueryFunction<PaginationResult<TRow>, ...>Data fetch function
queryParamsTParamsAdditional query parameters
queryEnabled(params?) => booleanWhether to enable the query
isPaginatedbooleantrueEnable/disable pagination
showSequenceColumnbooleantrueShow row number column
virtualbooleanfalseEnable virtual scrolling
stripedbooleanfalseRender zebra-striped rows
columnSettingsColumnSettingsConfig | false{}Column visibility settings
operationColumnOperationColumnConfig<TRow>Per-row action column
rowSelectionRowSelectionConfig<TRow> | trueRow selection config
selectedRowKeysKey[]Controlled selected row keys
size'large' | 'medium' | 'small'Table density ('middle' is a deprecated alias for 'medium')
titleReactNodeTitle above the table
headerReactNodeContent above the title
summaryReactNodeContent below the table
footerReactNodeFooter content
classNamestringClass for the table container
styleCSSPropertiesInline style for the table container
onRowClick(row, index, event) => voidRow click handler (ignored inside the operation column)
onSelectedRowKeysChange(keys, rows) => voidSelection change callback

ColumnSettingsConfig

interface ColumnSettingsConfig {
storageKey?: string; // persist to localStorage with this key
}

OperationColumnConfig<TRow>

FieldTypeDescription
widthLengthColumn width. No built-in default — set a fixed width so the end-fixed column doesn't absorb leftover table space; the framework convention is 160 px for a two-button action pair (which is also EditableTable's default)
titleReactNodeColumn header title; defaults to "操作". The column-settings icon is rendered next to it when column settings are enabled
requiredPermissionsstring[]Permission tokens required to display the operation column
render(row: TRow, index: number) => ReactNodeRender the operation cell for a row (required)

requiredPermissions hides the entire operation column (header included) when the current user doesn't hold any of the listed permission tokens. The operation column is always fixed to the end of the table.

RowSelectionConfig<TRow>

Passed as rowSelection (or pass true for all defaults):

FieldTypeDescription
rowSelectDisabled(model: TRow) => booleanDisable selection for rows where the function returns true
checkStrictlybooleanCheck table rows precisely, with parent and children selection not associated
hideSelectAllbooleanHide the select-all checkbox in the header
preserveSelectedRowKeysbooleanKeep selection keys even when the key no longer exists in dataSource
defaultSelectedRowKeysKey[]The initially selected row keys

ProTableRef

MemberTypeDescription
refetch() => voidManually trigger a data refetch (e.g. after external changes)
onLoading(callback: () => void) => () => voidRegister a callback invoked when the table starts loading; returns an unsubscribe function
onLoaded(callback: () => void) => () => voidRegister a callback invoked when the table finishes loading; returns an unsubscribe function

ProTableSubscriber

Subscribe to table loading events from outside the component:

import { ProTableSubscriber } from '@vef-framework-react/components';

<ProTableSubscriber
tableRef={tableRef}
onLoading={() => setLoading(true)}
onLoaded={() => setLoading(false)}
/>