Table Header
Documentation for the table header component in React Table Grid
Table Header 📋
The TableHeader
component is responsible for rendering the header section of your table. It's where your column titles live and handles features like sorting, column resizing, and pinning columns. Think of it as the top part of your table that helps users understand and organize the data below!
Features 🎯
- 📊 Column headers with sorting
- 📌 Pin columns to left or right
- ↔️ Resize columns easily
- 📱 Sticky header while scrolling
- 🎨 Easy to style and customize
Basic Usage
Here's a simple example of how to use the TableHeader:
Props
Required Props
tableInstance
The table instance from useTableGrid hook that manages the table state.
Optional Props
className
Add custom CSS classes to the header.
style
Add custom inline styles.
enableColumnResize
Let users resize columns by dragging.
- Type:
boolean
- Default:
false
TableColumnClassName
Add custom CSS classes to each column header.
headerRowClassName
Add custom CSS classes to the header row.
withoutTailwind
Use without Tailwind CSS (for custom styling).
- Type:
boolean
- Default:
false
Advanced Features
1. Pinned Columns
You can pin columns to the left or right side of the table:
2. Column Resizing
Enable column resizing with a simple prop:
3. Custom Styling
Style your header exactly how you want:
4. Without Tailwind
If you're not using Tailwind CSS:
Examples
Basic Header with Sorting
Header with Pinned Columns
Resizable Header
Styling Guide
With Tailwind (Default)
Without Tailwind
Best Practices 💡
- Keep Headers Clear: Use short, descriptive column headers
- Enable Sorting: Add sorting for columns where it makes sense
- Pin Important Columns: Pin frequently referenced columns
- Responsive Design: Make sure headers work well on mobile
- Consistent Styling: Keep header styles consistent with your app
- Handle Overflow: Use ellipsis for long header text
- Accessibility: Include proper ARIA labels
Related Components
Last updated on