colspan attribute in HTML tables. This is useful for creating merged cells, section headers, or full-width content rows.
Basic Usage
Use thecolSpan function on a column to control spanning:
Visual Result
Visual Result
colSpan Function
ThecolSpan function determines how many columns a cell should span:
undefinedornull: No spanning (default)number: Number of columns to span (including the current column)
- ROW Type
- HEADER Type
- SUMMARY Type
Common Use Cases
Section Headers
Create full-width section headers within your data:Merged Cells
Merge cells based on data relationships:Conditional Spanning
Span based on cell content:Spanning with Frozen Columns
Cells can span across frozen and non-frozen columns:From src/utils/colSpan.ts:Frozen columns cannot span beyond the last frozen column boundary.
Spanning in Summary Rows
Span summary cells across multiple columns:Styling Spanned Cells
Apply custom styles to spanned cells:Accessibility
The grid automatically sets appropriatearia-colspan attributes:
Performance Considerations
Impact on Rendering
Impact on Rendering
Cell spanning requires additional calculations:
- colSpan evaluation: Called for each visible cell
- Layout recalculation: CSS Grid adjusts for spanning cells
- Virtual scrolling: Spanning cells are properly handled
- Keep
colSpanfunctions simple and fast - Avoid expensive calculations inside
colSpan - Use memoization if calculations are complex
Limitations
Current Limitations:
- No Row Spanning: Cells cannot span multiple rows (only columns)
- Frozen Column Boundary: Frozen columns cannot span beyond the last frozen column
- Manual Rendering: Spanned cells don’t automatically merge content from hidden columns
- Selection: Cell selection works on the spanned cell, not individual underlying columns
Advanced Example: Tree Table
Combine spanning with custom rendering for tree-like structures:API Reference
Column Property
colSpan
args: Object with type discriminator and row data
undefinedornull: No spanningnumber: Number of columns to span (must be ≥ 1)
ColSpanArgs Type
type: 'HEADER': Header row (no row data)type: 'ROW': Regular data row (includesrowproperty)type: 'SUMMARY': Summary row (includesrowproperty with summary data)
Related Features
- Column Grouping - Group columns under shared headers
- Summary Rows - Spanning in summary rows
- Custom Renderers - Custom rendering for spanned cells