Documentation
Column Sorting
Column sorting allows users to organize table data in ascending or descending order based on column values. This feature is essential for data analysis and quick information retrieval.
Basic Sorting
To enable sorting for a column, add the isSortable: true property to your column definition.
✨ New in v1.9.4: Array Index Support
Accessors now support nested array paths using bracket notation. This allows you to sort by specific array elements without writing custom logic.
awards[0]- Sort by first awardalbums[0].title- Sort by first album's titlereleaseDate[0]- Sort by first release date
Column Sorting Configuration
Advanced Sorting
For complex sorting scenarios, Simple Table provides two powerful options:
Custom Comparator
Use comparator when you need to sort based on multiple fields, row metadata, or custom business logic:
💡 Use Cases
- Sort by multiple fields with priority (e.g., priority level + performance score)
- Access metadata or related fields not directly in the column
- Implement domain-specific sorting rules (e.g., custom status ordering)
- Sort by computed values derived from multiple row properties
Value Getter
Use valueGetter to extract nested values or compute values for sorting, especially when displaying formatted text:
💡 Use Cases
- Sort by nested/computed values while displaying formatted text
- Access deeply nested properties (e.g., row.metadata.seniorityLevel)
- Calculate derived values for sorting operations
- Combine with valueFormatter to separate sorting logic from display
🎯 Comparator vs ValueGetter
Use comparator when you need full control over the sorting logic with access to both rows. Use valueGetter when you want the default sorting behavior but need to extract or compute the value first.
Initial Sort State
Set the table to load with a default sort applied using initialSortColumn and initialSortDirection. This is perfect for showing users the most relevant data first, like sorting by date (newest first) or revenue (highest first).
💡 Use Cases
- Sort by date to show newest records first
- Sort by revenue/sales to highlight top performers
- Sort by priority or status to show critical items first
- Provide a consistent, predictable initial view for users
1<SimpleTable2 defaultHeaders={headers}3 rows={data}4 initialSortColumn="revenue" // Sort by revenue column5 initialSortDirection="desc" // Show highest revenue first6 // ... other props7/>
The table will load with the sort applied, and users can still change the sort by clicking column headers.
External Sorting
For advanced use cases, you can handle sorting externally - perfect for server-side sorting, API integration, or custom sorting logic. This demo shows how to manage sorting completely outside the table component.
External Sort Status: No sorting applied
External sorting provides two key benefits:
- API Integration: Use
onSortChangeto trigger server-side sorting while keeping the table's UI sorting indicators. - Complete Control: Use
externalSortHandling=to disable all internal sorting and provide your own pre-sorted data.