Basic Search Example
Learn how to implement basic search functionality in React Table Grid
This example demonstrates how to implement basic search functionality in your table. You'll learn how to enable filtering and handle search state changes.
Overview
The basic search example shows how to:
- Enable table filtering
- Handle search state changes
- Use the classic variant styling
- Configure sortable columns
Example
Basic Search
Type to filter table content. Results will update as you type.
Key Features Explained
1. Enabling Search
To enable search functionality, set the enableFiltering
prop to true
:
2. Column Configuration
Each column can be configured for sorting:
3. State Management
Track table state changes using the onStateChange
prop:
Props Used
Prop | Type | Description |
---|---|---|
enableFiltering | boolean | Enables the search functionality |
variant | "classic" | Sets the visual style of the table |
maxHeight | string | Sets the maximum height of the table |
onStateChange | function | Callback for table state changes |
Customization Options
1. Search Input Styling
You can customize the search input appearance using the styleConfig
prop:
2. Search Placeholder
Customize the search placeholder text:
Best Practices
- Type Safety: Always define your data types and use
createColumnHelper
- State Management: Handle state changes appropriately for your use case
- Error Handling: Add error boundaries and loading states
- Accessibility: Ensure proper ARIA labels for the search input
Common Issues and Solutions
Search Not Working
If the search functionality isn't working:
- Verify
enableFiltering
is set totrue
- Check that your data structure matches the column accessors
- Ensure you're not overriding the filtered data accidentally
Performance Issues
If you experience performance issues with large datasets:
- Consider implementing debounced search
- Use virtualization for large data sets
- Implement server-side filtering
Next Steps
- Try implementing Fuzzy Search
Last updated on