Table
Brief Introduction
The Table component is used to display structured data, supporting tree data, selection functionality, custom styles, and more. You can use <MYTable></MYTable> to implement a table component. Column structure can be defined via props.columns or the child component <MYTableColumn>. Custom content requires named slots.
Basic Table
Basic Table
Define table structure and data using columns and data properties.
| Name | Age | Address |
|---|---|---|
| John | 25 | Chaoyang District, Beijing |
| Jane | 30 | Pudong New Area, Shanghai |
| Bob | 28 | Tianhe District, Guangzhou |
展开代码
Define Columns Using Slots
Define Columns Using Slots
Use the MYTableColumn component and slots to customize column content.
| Name | Age | Address | Status |
|---|---|---|---|
| John | 25 | Chaoyang District, Beijing | Success |
| Jane | 30 | Pudong New Area, Shanghai | Failed |
| Bob | 28 | Tianhe District, Guangzhou | Success |
展开代码
Selection Feature
Selection Feature
Enable row selection using a type='selection' column.
| Name | Age | Address | |
|---|---|---|---|
| John | 25 | Chaoyang District, Beijing | |
| Jane | 30 | Pudong New Area, Shanghai | |
| Bob | 28 | Tianhe District, Guangzhou |
Selected:
展开代码
Tree Data
Tree Data
Use tree-structured data to display hierarchical relationships.
| Department | Manager | Headcount |
|---|---|---|
| Engineering | Zhang | 20 |
| Marketing | Zhao | 15 |
展开代码
Striped Table
Striped Table
Add zebra striping style using the stripe property.
| Name | Department | Position | Salary |
|---|---|---|---|
| John | Engineering | Frontend Dev | 15000 |
| Jane | Engineering | Backend Dev | 16000 |
| Bob | Marketing | Marketing Mgr | 14000 |
| Alice | HR | HR Specialist | 12000 |
展开代码
Column Alignment
Column Alignment
Control column content alignment using align, headerAlign, and bodyAlign.
| Name (Left) | Age (Center) | Salary (Right) | Bonus |
|---|---|---|---|
| John | 25 | 15000 | 5000 |
| Jane | 30 | 16000 | 6000 |
| Bob | 28 | 14000 | 4500 |
展开代码
Table with Pagination
Table with Pagination
Implement table pagination using the pagination slot.
| Name | Age | Address |
|---|---|---|
| John | 25 | Chaoyang District, Beijing |
| Jane | 30 | Pudong New Area, Shanghai |
展开代码
API Reference
Table Props
| Parameter | Description | Type | Optional Values | Default |
|---|---|---|---|---|
| data | Table data | Array | — | [] |
| columns | Column configuration | TableColumnProps[] | — | [] |
| width | Table width | string | — | '' |
| height | Table height | string | — | '' |
| headerBackgroundColor | Header background color | string | Hex or named colors | '' |
| headerTextColor | Header text color | string | Hex or named colors | '' |
| stripe | Stripe color | string | Hex or named colors | '' |
| borderColor | Border color | string | Hex or named colors | '' |
| bodyBackgroundColor | Table body background color | string | Hex or named colors | '' |
| bodyTextColor | Table body text color | string | Hex or named colors | '' |
| rowKey | Row data key | string | — | 'id' |
| treeProps | Tree structure config | object | — | { children: 'children', hasChildren: 'hasChildren' } |
| indent | Tree data indent | number | — | 16 |
| align | Content alignment | string | left / center / right | 'left' |
| headerAlign | Header alignment | string | left / center / right | '' |
| bodyAlign | Body alignment | string | left / center / right | '' |
TableColumn Props
| Parameter | Description | Type | Optional Values | Default |
|---|---|---|---|---|
| prop | Column data key | string | — | — |
| label | Column header label | string | — | undefined |
| width | Column width | string | — | '' |
| type | Column type | string | selection | '' |
| align | Content alignment | string | left / center / right | '' |
| headerAlign | Header alignment | string | left / center / right | '' |
| bodyAlign | Body alignment | string | left / center / right | '' |
Table Events
| Event Name | Description | Parameters |
|---|---|---|
| selection-change | Triggers when selection changes | selection: any[] |
| update:modelValue | Triggers when selected row data changes | value: any[] |
Type Definitions
typescript
interface TableColumnProps {
className: string;
prop: string;
label?: string;
width?: string;
height?: string;
fixed?: 'left' | 'right';
sortable?: boolean;
filterable?: boolean;
filters?: Array<{ text: string; value: string | number }>;
scopedSlot?: string;
children?: TableColumnProps[];
colspan?: number;
rowspan?: number;
type?: string;
align?: 'left' | 'center' | 'right';
headerAlign?: 'left' | 'center' | 'right';
bodyAlign?: 'left' | 'center' | 'right';
}
interface TableProps {
data?: Record<string, unknown>[];
modelValue?: string;
columns?: TableColumnProps[];
width?: string;
height?: string;
headerColor?: string;
headerTextColor?: string;
stripe?: string;
borderColor?: string;
bodyBackgroundColor?: string;
bodyTextColor?: string;
[key: string]: unknown;
}