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

PropertyRequiredDescriptionExample
rowHeight
number
Optional
Height of table rows in pixels. This value is used for virtualization calculations and cannot be styled through CSS. If not specified, uses the default value of 40px.
headerHeight
number
Optional
Height of the table header in pixels. This value is used for virtualization calculations and cannot be styled through CSS. If not specified, uses the default value of 40px.
footerHeight
number
Optional
Height of the table footer in pixels. This value is used for virtualization calculations and cannot be styled through CSS. If not specified, uses the default value of 50px.
rowSeparatorWidth
number
Optional
Width of separators between rows in pixels. This value affects virtualization calculations and cannot be styled through CSS. If not specified, uses the default value of 1px.
borderWidth
number
Optional
General border width in pixels (e.g., table borders, header borders). This value affects layout calculations and cannot be styled through CSS. If not specified, uses the default value of 1px.
pinnedBorderWidth
number
Optional
Width of borders for pinned columns in pixels. This value affects layout calculations for pinned columns and cannot be styled through CSS. If not specified, uses the default value of 2px.
nestedGridBorderWidth
number
Optional
Border width for nested grid tables (top + bottom) in pixels. This value affects nested table layout calculations and cannot be styled through CSS. If not specified, uses the default value of 2px.
nestedGridPaddingTop
number
Optional
Top padding for nested grids in pixels. This value affects nested table layout calculations and cannot be styled through CSS. If not specified, uses the default value of 8px.
nestedGridPaddingBottom
number
Optional
Bottom padding for nested grids in pixels. This value affects nested table layout calculations and cannot be styled through CSS. If not specified, uses the default value of 8px.
nestedGridPaddingLeft
number
Optional
Left padding for nested grids in pixels. This value affects nested table layout calculations and cannot be styled through CSS. If not specified, uses the default value of 16px.
nestedGridPaddingRight
number
Optional
Right padding for nested grids in pixels. This value affects nested table layout calculations and cannot be styled through CSS. If not specified, uses the default value of 16px.
nestedGridMaxHeight
number
Optional
Maximum height for nested grids in pixels. This value controls how tall nested tables can grow before scrolling. If not specified, nested grids will grow to fit their content.
selectionColumnWidth
number
Optional
Width of the row selection checkbox column in pixels. This value affects layout calculations and cannot be styled through CSS. If not specified, uses the default value of 40px.

Example Usage

React TSX
1import { SimpleTable } from 'simple-table-core';
2import 'simple-table-core/styles.css';
3
4export default function MyTable() {
5 return (
6 <SimpleTable
7 defaultHeaders={headers}
8 rows={data}
9 customTheme={{
10 // Row and header dimensions
11 rowHeight: 48,
12 headerHeight: 56,
13 footerHeight: 60,
14
15 // Border widths
16 rowSeparatorWidth: 1,
17 borderWidth: 2,
18 pinnedBorderWidth: 3,
19
20 // Nested grid configuration
21 nestedGridBorderWidth: 2,
22 nestedGridPaddingTop: 12,
23 nestedGridPaddingBottom: 12,
24 nestedGridPaddingLeft: 20,
25 nestedGridPaddingRight: 20,
26 nestedGridMaxHeight: 400,
27
28 // Column dimensions
29 selectionColumnWidth: 50,
30 }}
31 />
32 );
33}

Common Use Cases

  • Compact tables - Reduce rowHeight to 32px for dense data displays
  • Spacious layouts - Increase rowHeight to 56px or more for better readability
  • Nested tables - Configure nestedGridMaxHeight to 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:

  1. Create a CSS file with your theme variables using the .theme-custom class
  2. Import the CSS file into your application
  3. Apply the theme by passing theme="custom" to the SimpleTable component

CSS Theme Configuration

PropertyRequiredDescriptionExample
theme
Optional
Set to "custom" to apply your custom CSS theme. Requires a corresponding CSS file with .theme-custom class and CSS variables.

Theme Variable Tips

  • Use the .theme-custom class 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:

React TSX
1

Combining Both Approaches

You can use both CSS theming and the customTheme prop together for complete control over your table's appearance:

React TSX
1import { SimpleTable } from 'simple-table-core';
2import 'simple-table-core/styles.css';
3import './my-custom-theme.css'; // Your CSS variables
4
5export default function MyTable() {
6 return (
7 <SimpleTable
8 defaultHeaders={headers}
9 rows={data}
10 // CSS theming for colors and visual styling
11 theme="custom"
12 // Layout dimensions for virtualization
13 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.