ShakibDShy

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

Name
Age
Email
Adrian Brown
38
adrian.b@company.com
Alexander Davis
37
alex.d@company.com
Amelia Moore
35
amelia.m@company.com
Andrew Wilson
44
andrew.w@company.com
Aria Davis
31
aria.d@company.com
Aurora White
32
aurora.w@company.com
Ava Martinez
33
ava.m@company.com
Benjamin Taylor
39
ben.t@company.com
Charlotte Wilson
31
charlotte.w@company.com
Christopher Moore
38
chris.m@company.com
Daniel White
35
daniel.w@company.com
David Lee
37
david.l@company.com
Elena Anderson
34
elena.a@company.com
Elijah Thompson
40
elijah.t@company.com
Emily Davis
29
emily.d@company.com
Emma Rodriguez
30
emma.r@company.com
Ethan Anderson
40
ethan.a@company.com
Felix Wilson
41
felix.w@company.com
Gabriel Martinez
37
gabriel.m@company.com
Hazel Garcia
33
hazel.g@company.com
Henry Garcia
43
henry.g@company.com
Isabella Thompson
31
isabella.t@company.com
Jack Thompson
41
jack.t@company.com
James Taylor
39
james.t@company.com
Jane Smith
34
jane.smith@company.com
Jennifer Martinez
36
jennifer.m@company.com
John Doe
28
john.doe@company.com
Leo Wilson
42
leo.w@company.com
Lily Moore
33
lily.m@company.com
Lisa Anderson
33
lisa.a@company.com
Lucas Brown
37
lucas.b@company.com
Luna Rodriguez
30
luna.r@company.com
Matthew Brown
36
matthew.b@company.com
Max Lee
36
max.l@company.com
Maya Rodriguez
34
maya.r@company.com
Mia Johnson
34
mia.j@company.com
Michael Wilson
45
michael.w@company.com
Noah Clark
39
noah.c@company.com
Olivia Garcia
29
olivia.g@company.com
Owen Martinez
38
owen.m@company.com
Robert Johnson
41
robert.j@company.com
Ruby Anderson
31
ruby.a@company.com
Sarah Brown
31
sarah.b@company.com
Scarlett White
33
scarlett.w@company.com
Sebastian Clark
36
sebastian.c@company.com
Sophia Lee
32
sophia.l@company.com
Stella Davis
35
stella.d@company.com
Victoria Lee
32
victoria.l@company.com
William Clark
42
william.c@company.com
Zoe Garcia
35
zoe.g@company.com

Key Features Explained

To enable search functionality, set the enableFiltering prop to true:

<TableGrid
  enableFiltering={true}
  // ... other props
/>

2. Column Configuration

Each column can be configured for sorting:

columnHelper.accessor("name", {
  header: "Name",
  sortable: true, // Enable sorting for this column
})

3. State Management

Track table state changes using the onStateChange prop:

onStateChange={(state) => {
  console.log("Table state changed:", state);
  // Access search value: state.filterValue
  // Access filtered data: state.data
}}

Props Used

PropTypeDescription
enableFilteringbooleanEnables the search functionality
variant"classic"Sets the visual style of the table
maxHeightstringSets the maximum height of the table
onStateChangefunctionCallback for table state changes

Customization Options

1. Search Input Styling

You can customize the search input appearance using the styleConfig prop:

<TableGrid
  styleConfig={{
    utilityStyles: {
      searchContainer: "p-4 border-b",
    },
  }}
  // ... other props
/>

2. Search Placeholder

Customize the search placeholder text:

<TableGrid
  filterPlaceholder="Search items..."
  // ... other props
/>

Best Practices

  1. Type Safety: Always define your data types and use createColumnHelper
  2. State Management: Handle state changes appropriately for your use case
  3. Error Handling: Add error boundaries and loading states
  4. Accessibility: Ensure proper ARIA labels for the search input

Common Issues and Solutions

Search Not Working

If the search functionality isn't working:

  1. Verify enableFiltering is set to true
  2. Check that your data structure matches the column accessors
  3. Ensure you're not overriding the filtered data accidentally

Performance Issues

If you experience performance issues with large datasets:

  1. Consider implementing debounced search
  2. Use virtualization for large data sets
  3. Implement server-side filtering

Next Steps

Last updated on

On this page