Basic Table Example
Learn how to create a simple table with React Table Grid
This example demonstrates how to create a basic table using React Table Grid. It's the perfect starting point for beginners to understand the core concepts.
Overview
The basic table example shows how to:
- Set up a basic table structure
- Define typed columns
- Handle basic state changes
- Configure table height
Example
Step-by-Step Guide
1. Define Data Types
First, define the shape of your data using TypeScript:
2. Create Column Helper
Use createColumnHelper
to get type-safe column definitions:
3. Define Columns
Create your column definitions using the column helper:
4. Create Table Component
Implement the table component with the required props:
Core Props Explained
Prop | Type | Required | Description |
---|---|---|---|
columns | Column<T>[] | Yes | Column definitions |
data | T[] | Yes | Table data array |
maxHeight | string | No | Maximum table height |
onStateChange | function | No | State change callback |
Basic Customization
1. Styling
Add basic styling using the styleConfig
prop:
2. Height Configuration
Control table height:
State Management
Basic State Tracking
Monitor table state changes:
Best Practices
-
Type Safety
- Always define proper TypeScript interfaces
- Use
createColumnHelper
for type-safe columns
-
Performance
- Keep data structures flat when possible
- Avoid unnecessary re-renders
- Consider memoization for large datasets
-
Code Organization
- Separate column definitions from component logic
- Use consistent naming conventions
- Document complex configurations
Common Issues and Solutions
Table Not Rendering
If the table isn't rendering:
- Check that
columns
anddata
props are properly defined - Verify data structure matches column accessors
- Ensure container has proper dimensions
Type Errors
If you're getting TypeScript errors:
- Verify your data type definitions
- Check column accessor keys match data properties
- Ensure proper generic types are passed to components
Related Examples
Last updated on