Skip to content

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.
NameAgeAddress
John25Chaoyang District, Beijing
Jane30Pudong New Area, Shanghai
Bob28Tianhe District, Guangzhou
展开代码

Define Columns Using Slots ​

Define Columns Using Slots
Use the MYTableColumn component and slots to customize column content.
NameAgeAddressStatus
John25Chaoyang District, BeijingSuccess
Jane30Pudong New Area, ShanghaiFailed
Bob28Tianhe District, GuangzhouSuccess
展开代码

Selection Feature ​

Selection Feature
Enable row selection using a type='selection' column.
NameAgeAddress
John25Chaoyang District, Beijing
Jane30Pudong New Area, Shanghai
Bob28Tianhe District, Guangzhou
Selected:
展开代码

Tree Data ​

Tree Data
Use tree-structured data to display hierarchical relationships.
DepartmentManagerHeadcount
EngineeringZhang20
MarketingZhao15
展开代码

Striped Table ​

Striped Table
Add zebra striping style using the stripe property.
NameDepartmentPositionSalary
JohnEngineeringFrontend Dev15000
JaneEngineeringBackend Dev16000
BobMarketingMarketing Mgr14000
AliceHRHR Specialist12000
展开代码

Column Alignment ​

Column Alignment
Control column content alignment using align, headerAlign, and bodyAlign.
Name (Left)Age (Center)Salary (Right)Bonus
John25150005000
Jane30160006000
Bob28140004500
展开代码

Table with Pagination ​

Table with Pagination
Implement table pagination using the pagination slot.
NameAgeAddress
John25Chaoyang District, Beijing
Jane30Pudong New Area, Shanghai
展开代码

API Reference ​

Table Props ​

ParameterDescriptionTypeOptional ValuesDefault
dataTable dataArray—[]
columnsColumn configurationTableColumnProps[]—[]
widthTable widthstring—''
heightTable heightstring—''
headerBackgroundColorHeader background colorstringHex or named colors''
headerTextColorHeader text colorstringHex or named colors''
stripeStripe colorstringHex or named colors''
borderColorBorder colorstringHex or named colors''
bodyBackgroundColorTable body background colorstringHex or named colors''
bodyTextColorTable body text colorstringHex or named colors''
rowKeyRow data keystring—'id'
treePropsTree structure configobject—{ children: 'children', hasChildren: 'hasChildren' }
indentTree data indentnumber—16
alignContent alignmentstringleft / center / right'left'
headerAlignHeader alignmentstringleft / center / right''
bodyAlignBody alignmentstringleft / center / right''

TableColumn Props ​

ParameterDescriptionTypeOptional ValuesDefault
propColumn data keystring——
labelColumn header labelstring—undefined
widthColumn widthstring—''
typeColumn typestringselection''
alignContent alignmentstringleft / center / right''
headerAlignHeader alignmentstringleft / center / right''
bodyAlignBody alignmentstringleft / center / right''

Table Events ​

Event NameDescriptionParameters
selection-changeTriggers when selection changesselection: any[]
update:modelValueTriggers when selected row data changesvalue: 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;
}

Released under the MIT License.