Table header component for displaying table column titles, supports sorting, custom alignment and column width settings.
Features
- π Column Configuration - Flexible column configuration with width, alignment and other properties
- π Sorting Function - Supports column sorting with three states: none, ascending, descending
- π¨ Custom Styles - Rich CSS variables for theme customization
- π§ Slot Support - Support custom column header content
- π± Responsive - Adapt to different screen sizes
- β‘ Lightweight & Efficient - Optimized code structure with excellent performance
Use Cases
- Data list display
- Leaderboard header
- Schedule table header
- Score table header
- Any scenario requiring table display
Import
Code Demo
Basic Usage
Support Sorting
Custom Column Width and Alignment
Custom Column Header
API
Props
| Parameter | Description | Type | Default |
| columns | Column config array | Column[] | [] |
| custom-class | Custom style class | string | '' |
Column Data Structure
Slots
| Name | Description | Parameters |
| header-{key} | Custom column header content, {key} is the column key | { column: Column } |
Events
| Event | Description | Parameters |
| sort | Triggered when sort click | { key: string, order: 'asc' \| 'desc' \| null } |
Notes
Usage Recommendations
- Column Width Setting: Recommend using rem unit for column width to ensure consistency across devices
- Alignment: Numeric data should use
center or right alignment, text data should use left alignment - Sorting Function: Sorting state cycles through three states: none β ascending β descending β none
- Minimum Width: Use
minWidth to set minimum column width to prevent content compression - Custom Header: Use
header-{key} slot to fully customize column header display
- Recommend wrapping column config with
ref to avoid unnecessary re-renders - For many columns, recommend setting fixed width to avoid frequent browser calculations
- Recommend debouncing sort operations
Compatibility
- Supports Vue 3.0+
- Compatible with modern browsers (Chrome 60+, Firefox 60+, Safari 12+)
- Supports WeChat Mini Program, Alipay Mini Program and other platforms
Theme Customization
The component provides the following CSS variables for custom styling. Please refer to the ConfigProvider component for usage.
Style Variables
Spacing System
| Name | Default | Description |
| --pmth-header-cell-padding | 0 | Header cell padding |
| --pmth-header-cell-padding-left | $spacing-md | Header left padding |
| --pmth-sort-icon-margin-left | .08rem | Sort icon left margin |
| --pmth-sort-arrow-margin-bottom | .02rem | Sort arrow bottom margin |
Box Model System
| Name | Default | Description |
| --pmth-table-header-width | 100% | Table header width |
| --pmth-table-header-container-width | 100% | Table header container width |
| --pmth-header-overflow-x | auto | Header horizontal overflow |
| --pmth-header-height | .7rem | Header height |
| --pmth-header-cell-min-width | 1.4rem | Header cell minimum width |
| --pmth-sort-icon-size | .24rem | Sort icon size |
| --pmth-sort-arrow-size | .08rem | Sort arrow size |
Color System
| Name | Default | Description |
| --pmth-table-header-container-bg-color | transparent | Table header container background color |
| --pmth-table-header-container-bg-image | url(...) | Table header container background image |
| --pmth-table-header-container-bg-size | 100% 100%, 100% 100%, cover | Table header container background size |
| --pmth-table-header-container-bg-position | center, center, center | Table header container background position |
| --pmth-table-header-container-bg-repeat | no-repeat, no-repeat, no-repeat | Table header container background repeat |
| --pmth-header-cell-color | $color-text-invert-light | Header cell text color |
| --pmth-sort-arrow-color | #adb5bd | Sort arrow color |
| --pmth-sort-arrow-active-color | $color-surface-brand | Active sort arrow color |
Typography System
| Name | Default | Description |
| --pmth-header-cell-font-size | $font-size-xs | Header cell font size |
| --pmth-header-cell-font-weight | $font-weight-regular | Header cell font weight |
| --pmth-header-cell-line-height | 1.5 | Header cell line height |
Others
| Name | Default | Description |
| --pmth-table-header-position | relative | Table header position |
| --pmth-table-header-container-position | relative | Table header container position |
| --pmth-header-cell-position | relative | Header cell position |
| --pmth-sort-icon-position | relative | Sort icon position |
| --pmth-header-cell-sortable-user-select | none | Sortable header cell user select |
| --pmth-header-cell-justify-content-left | flex-start | Header cell left align |
| --pmth-header-cell-justify-content-center | center | Header cell center align |
| --pmth-header-cell-justify-content-right | flex-end | Header cell right align |