A powerful, feature-rich data grid component built with React and TypeScript. This component provides advanced filtering, grouping, column management, export capabilities, and much more.
- 🔍 Advanced Filtering - Text, date range, number range, and multi-select filters
- 📊 Smart Grouping - Multi-level grouping with templates and aggregations
- 🎛️ Column Management - Show/hide, pin, resize, and reorder columns
- 📤 Export Options - Export to CSV, Excel, JSON, XML, PDF, HTML, SQL, Markdown, and Text
- ⌨️ Keyboard Shortcuts - Comprehensive keyboard navigation and actions
- 🎨 Customization - Custom renderers, grouped headers, and themes
- 📱 Responsive - Works on desktop, tablet, and mobile devices
- ♿ Accessible - WCAG compliant with screen reader support
```bash npm install @/components/data-grid ```
```tsx import DataGrid from '@/components/data-grid'
const columns = [ { key: 'id', title: 'ID', type: 'number' }, { key: 'name', title: 'Name', type: 'text', sortable: true, filterable: true }, { key: 'email', title: 'Email', type: 'text', filterable: true }, { key: 'salary', title: 'Salary', type: 'currency', sortable: true, filterable: true } ]
const data = [ { id: 1, name: 'John Doe', email: 'john@example.com', salary: 75000 }, { id: 2, name: 'Jane Smith', email: 'jane@example.com', salary: 85000 } ]
function MyComponent() { return ( ) } ```
| Prop | Type | Default | Description |
|---|---|---|---|
data |
any[] |
Required | Array of data objects to display |
columns |
Column[] |
Required | Column configuration array |
pageSize |
number |
10 |
Number of rows per page |
allowSelection |
boolean |
false |
Enable row selection with checkboxes |
allowGrouping |
boolean |
false |
Enable drag-and-drop grouping |
allowExport |
boolean |
false |
Enable export functionality |
allowColumnResize |
boolean |
false |
Enable column resizing |
allowColumnReorder |
boolean |
false |
Enable column reordering |
onColumnOrderChange |
(order: string[]) => void |
- | Callback when column order changes |
```tsx interface Column { key: string // Unique identifier for the column title: string // Display title in header sortable?: boolean // Enable sorting for this column filterable?: boolean // Enable filtering for this column width?: number // Initial column width in pixels type?: 'text' | 'number' | 'date' | 'currency' // Data type for formatting filterType?: 'text' | 'dateRange' | 'numberRange' | 'multiSelect' filterOptions?: string[] // Options for multiSelect filter columns?: Column[] // Sub-columns for grouped headers render?: (row: any) => React.ReactNode // Custom cell renderer pinnable?: boolean // Allow pinning this column } ```
- text: Plain text with string filtering
- number: Numeric values with range filtering
- date: Date values with date range filtering
- currency: Formatted currency values with range filtering
- text: Simple text search
- dateRange: Date range picker with from/to dates
- numberRange: Number range with min/max inputs
- multiSelect: Dropdown with multiple selection options
The data grid supports multiple filter types and operators:
```tsx // Text filter - searches within text content { key: 'name', title: 'Name', type: 'text', filterable: true }
// Date range filter - filter between two dates { key: 'createdAt', title: 'Created', type: 'date', filterType: 'dateRange', filterable: true }
// Number range filter - filter between min/max values { key: 'salary', title: 'Salary', type: 'currency', filterType: 'numberRange', filterable: true }
// Multi-select filter - select from predefined options { key: 'status', title: 'Status', type: 'text', filterType: 'multiSelect', filterOptions: ['Active', 'Inactive', 'Pending'], filterable: true } ```
- AND: All filters must match (default)
- OR: Any filter can match
- Switch between operators using the filter summary panel
- Undo:
Ctrl+Zor use the undo button - Redo:
Ctrl+YorCtrl+Shift+Z - Clear All:
Deletekey or clear all button
Enable grouping by setting allowGrouping={true}:
- Drag columns from the header to the grouping panel
- Multi-level grouping - drag multiple columns for nested groups
- Group templates - customize how group headers appear
- Aggregations - show sum, average, min, max, count for grouped data
```tsx // Built-in templates
- Default: "{{groupKey}}: {{groupValue}} ({{itemCount}} items)"
- Compact: "{{groupValue}} ({{itemCount}})"
- Detailed: "{{groupKey}}: {{groupValue}} | {{itemCount}} items | Total: {{sum_salary}}"
// Custom template variables
- {{groupKey}} - Column title
- {{groupValue}} - Group value
- {{itemCount}} - Number of items in group
- {{sum_columnName}} - Sum aggregation
- {{avg_columnName}} - Average aggregation
- {{min_columnName}} - Minimum value
- {{max_columnName}} - Maximum value
- {{count_columnName}} - Count of non-null values
- {{uniqueCount_columnName}} - Count of unique values ```
- Individual: Toggle columns on/off
- Bulk operations: Show/hide selected columns
- Type-based: Show only numbers, text, or dates
- Presets: Essential columns only
- Left pinning: Keep columns visible on the left
- Right pinning: Keep columns visible on the right
- Visual indicators: Pinned columns have distinct borders
- Manual: Drag column borders to resize
- Auto-size: Automatically fit content
- Distribute: Evenly distribute available width
- Drag and drop: Drag column headers to reorder
- Management panel: Use up/down arrows in column panel
- Restrictions: Pinned columns cannot be reordered
Export data in multiple formats with customization options:
- CSV - Comma-separated values
- Excel - Microsoft Excel format (.xlsx)
- JSON - JavaScript Object Notation
- XML - Extensible Markup Language
- PDF - Portable Document Format
- HTML - HTML table format
- SQL - SQL INSERT statements
- Markdown - Markdown table format
- Text - Plain text table
- Data scope: All data, filtered data, selected rows, or visible rows
- Column selection: Choose which columns to include
- Headers: Include/exclude column headers
- Formatting: Custom date formats, number formats, delimiters
- File naming: Custom filename with timestamp
?- Show keyboard shortcuts helpEsc- Close dialogs and clear selectionCtrl+F- Focus global searchDelete- Clear all filters
Ctrl+A- Select/deselect all rows
J- Next pageK- Previous pageHome- First pageEnd- Last pageAlt+N- Next page (alternative)Alt+P- Previous page (alternative)Alt+1- First page (alternative)Alt+0- Last page (alternative)
Alt+C- Toggle columns panelAlt+F- Toggle advanced settings panelCtrl+E- Open export dialog
Alt+M- Toggle compact modeAlt+R- Toggle row numbersAlt+S- Toggle summary rowAlt+H- Toggle all rows visibilityAlt+G- Toggle all groups (expand/collapse)
Ctrl+Z- Undo filter changesCtrl+Y- Redo filter changesCtrl+Shift+Z- Redo filter changes (alternative)
Create custom cell content with the render function:
```tsx const columns = [ { key: 'status', title: 'Status', render: (row) => ( <Badge variant={row.status === 'Active' ? 'success' : 'secondary'}> {row.status} ) }, { key: 'progress', title: 'Progress', render: (row) => (
${row.progress}% }}
/>
Organize columns into logical sections:
```tsx const columns = [ { key: 'personal', title: 'Personal Information', columns: [ { key: 'name', title: 'Name', type: 'text' }, { key: 'email', title: 'Email', type: 'text' } ] }, { key: 'employment', title: 'Employment Details', columns: [ { key: 'department', title: 'Department', type: 'text' }, { key: 'salary', title: 'Salary', type: 'currency' } ] } ] ```
```tsx interface Column { key: string title: string sortable?: boolean filterable?: boolean width?: number type?: "text" | "number" | "date" | "currency" filterType?: "text" | "dateRange" | "numberRange" | "multiSelect" filterOptions?: string[] columns?: Column[] render?: (row: any) => React.ReactNode pinnable?: boolean }
interface DataGridProps { data: any[] columns: Column[] pageSize?: number allowSelection?: boolean allowGrouping?: boolean allowExport?: boolean allowColumnResize?: boolean allowColumnReorder?: boolean onColumnOrderChange?: (newOrder: string[]) => void }
interface FilterPreset { id: string name: string filters: Record<string, any> filterOperator: "AND" | "OR" createdAt: string }
interface GroupConfig { columnKey: string title: string sortDirection: "asc" | "desc" expanded: boolean } ```
- Virtualization: For large datasets (>1000 rows), consider implementing virtual scrolling
- Memoization: Use
React.memofor custom renderers with complex logic - Debouncing: Filter inputs are debounced to prevent excessive re-renders
- Pagination: Use reasonable page sizes (10-100 rows)
- Loading states: Show loading indicators during data fetching
- Empty states: Provide helpful messages when no data is available
- Error handling: Display user-friendly error messages
- Responsive design: Test on different screen sizes
- Accessibility: Ensure keyboard navigation works properly
- Consistent data types: Ensure column types match your data
- Unique keys: Use unique identifiers for row keys
- Null handling: Handle null/undefined values gracefully
- Date formats: Use consistent date formats (ISO 8601 recommended)
Q: Columns are not sortable
A: Ensure sortable: true is set in the column configuration
Q: Filters are not working
A: Check that filterable: true is set and the column type matches your data
Q: Export is not available
A: Set allowExport={true} in the DataGrid props
Q: Drag and drop grouping doesn't work
A: Enable grouping with allowGrouping={true} and ensure columns are draggable
Q: Column resizing is not working
A: Set allowColumnResize={true} in the DataGrid props
Q: Performance is slow with large datasets A: Consider implementing pagination or virtual scrolling for datasets >1000 rows
- Chrome 90+
- Firefox 88+
- Safari 14+
- Edge 90+
The component follows WCAG 2.1 guidelines:
- Keyboard navigation support
- Screen reader compatibility
- High contrast mode support
- Focus management
- ARIA labels and roles
See the example files for complete implementations:
examples/simple-example.tsx- Basic product catalogexamples/basic-example.tsx- Employee directory with all featuresexamples/advanced-example.tsx- Sales dashboard with custom renderers
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests
- Submit a pull request
MIT License - see LICENSE file for details