Documentation
Custom Theme
Simple Table offers two complementary ways to customize your table's appearance: CSS-based theming for colors and visual styling, and the customTheme prop for layout dimensions that affect virtualization calculations.
Two Types of Customization
- CSS Theming - Use CSS variables to customize colors, fonts, and visual styles. Perfect for matching your design system.
- customTheme Prop - Configure layout dimensions (heights, widths, spacing) that affect virtualization calculations. These cannot be styled through CSS alone.
customTheme Prop: Layout Dimensions
The customTheme prop allows you to configure layout dimensions that are critical for the table's virtualization engine. These values determine how the table calculates scroll positions, visible rows, and layout measurements.
Why These Can't Be CSS-Only
Simple Table uses virtualization to efficiently render large datasets by only rendering visible rows. To calculate which rows are visible and where to position them, the table needs to know exact pixel dimensions before rendering. CSS values can't be read synchronously during render, so these dimensions must be provided as props.
customTheme Properties
Example Usage
1import { SimpleTable } from 'simple-table-core';2import 'simple-table-core/styles.css';34export default function MyTable() {5 return (6 <SimpleTable7 defaultHeaders={headers}8 rows={data}9 customTheme={{10 // Row and header dimensions11 rowHeight: 48,12 headerHeight: 56,13 footerHeight: 60,1415 // Border widths16 rowSeparatorWidth: 1,17 borderWidth: 2,18 pinnedBorderWidth: 3,1920 // Nested grid configuration21 nestedGridBorderWidth: 2,22 nestedGridPaddingTop: 12,23 nestedGridPaddingBottom: 12,24 nestedGridPaddingLeft: 20,25 nestedGridPaddingRight: 20,26 nestedGridMaxHeight: 400,2728 // Column dimensions29 selectionColumnWidth: 50,30 }}31 />32 );33}
Common Use Cases
- Compact tables - Reduce
rowHeightto 32px for dense data displays - Spacious layouts - Increase
rowHeightto 56px or more for better readability - Nested tables - Configure
nestedGridMaxHeightto control how tall nested grids can grow - Custom borders - Adjust border widths to match your design system
For a complete reference of all customTheme properties, see the API Reference.
CSS Theming: Colors and Visual Styling
Beyond the built-in themes, Simple Table allows you to create completely custom themes using CSS variables. By defining your own theme with custom colors, spacing, and typography, you can perfectly match your application's design system.
Creating a Custom CSS Theme
To create a custom CSS theme for Simple Table, follow these steps:
- Create a CSS file with your theme variables using the
.theme-customclass - Import the CSS file into your application
- Apply the theme by passing
theme="custom"to the SimpleTable component
CSS Theme Configuration
Theme Variable Tips
- Use the
.theme-customclass to define your custom theme - Define CSS variables with the
--st-prefix - Customize colors, spacing, fonts, and transitions
- Use direct hex values or color variables for consistent styling
- Test your theme with different features like column resizing and cell selection
CSS Variables Example
Here are the CSS variables used to create the custom theme in the demo above:
1
Combining Both Approaches
You can use both CSS theming and the customTheme prop together for complete control over your table's appearance:
1import { SimpleTable } from 'simple-table-core';2import 'simple-table-core/styles.css';3import './my-custom-theme.css'; // Your CSS variables45export default function MyTable() {6 return (7 <SimpleTable8 defaultHeaders={headers}9 rows={data}10 // CSS theming for colors and visual styling11 theme="custom"12 // Layout dimensions for virtualization13 customTheme={{14 rowHeight: 48,15 headerHeight: 56,16 nestedGridMaxHeight: 400,17 }}18 />19 );20}
Best Practice
Use CSS variables for all color and visual styling (backgrounds, borders, fonts, shadows), and use the customTheme prop for dimensions that affect layout calculations (heights, widths, spacing). This separation ensures optimal performance and maintainability.
New in v1.8.6: Sub-Column Styling
Version 1.8.6 introduces dedicated CSS variables for styling sub-columns (child columns within collapsible column groups). These variables give you fine-grained control over the appearance of nested column structures.
New Sub-Column CSS Variables
--st-sub-cell-hover-background-color- Background color when hovering over sub-cells--st-dragging-sub-header-background-color- Background color when dragging sub-headers--st-selected-sub-cell-background-color- Background color for selected sub-cells--st-selected-sub-cell-color- Text color for selected sub-cells
These variables complement the existing sub-column variables:
--st-sub-header-background-color- Background color for sub-column headers--st-sub-cell-background-color- Background color for sub-column cells
See the Collapsible Columns documentation for more details on using these variables.