A fully functional, dependency-free data grid built with React that replicates Syncfusion Grid functionality without external libraries.
This project demonstrates how to create a powerful data grid component from scratch using only React hooks and vanilla JavaScript. The grid includes all essential features like sorting, filtering, pagination, inline editing, and custom templates.
- Sorting: Click column headers to sort ascending/descending
- Filtering: Column-specific filters with global search
- Pagination: Configurable page sizes (5, 7, 10, 20)
- Inline Editing: Click cells to edit with validation
- Row Selection: Checkbox selection with bulk operations
- Add/Delete: Add new records and delete selected ones
- Custom Templates: Status badges and currency formatting
- Validation: Required fields, age ranges, minimum values
- Statistics Dashboard: Real-time stats cards
- Responsive Design: Modern UI with hover effects
- Keyboard Navigation: Enter to save, Escape to cancel
src/
components/
CustomDataGrid.jsx # Main grid component
DataGrid.jsx # Original Syncfusion version (for comparison)
App.tsx # Application entry point
import React from 'react';
import CustomDataGrid from './components/CustomDataGrid';
function App() {
return (
<div className="App">
<CustomDataGrid />
</div>
);
}const columns = [
{
field: 'id',
headerText: 'ID',
width: '70px',
textAlign: 'center',
isPrimaryKey: true,
allowEditing: false
},
{
field: 'name',
headerText: 'Full Name',
width: '160px',
textAlign: 'left',
validationRules: { required: true }
},
{
field: 'status',
headerText: 'Status',
width: '120px',
textAlign: 'center',
validationRules: { required: true },
editType: 'dropdown'
}
];// Status Badge Template
const StatusTemplate = ({ value }) => {
const isActive = value?.toLowerCase() === 'active';
return (
<span style={{
padding: '3px 10px',
borderRadius: '12px',
fontSize: '12px',
fontWeight: '600',
backgroundColor: isActive ? '#d1fae5' : '#fee2e2',
color: isActive ? '#065f46' : '#991b1b',
}}>
{value}
</span>
);
};
// Currency Template
const SalaryTemplate = ({ value }) => (
<span style={{ fontWeight: '500', color: '#1e40af' }}>
{'\u20b9' + value.toLocaleString('en-IN')}
</span>
);The CustomDataGrid component is self-contained and doesn't require any props. All data and configuration are handled internally.
The component uses React hooks for state management:
data: Master datasetfilteredData: Filtered datasetcurrentPage: Current page numberpageSize: Number of items per pagesortConfig: Current sorting configurationfilters: Column-specific filterseditingCell: Currently editing cellsearchTerm: Global search termselectedRows: Selected row IDs
handleSort(): Column sortinghandleFilter(): Column filteringhandleCellEdit(): Start cell editingsaveCellEdit(): Save edited cellhandleDelete(): Delete rowhandleAdd(): Add new rowhandleRowSelect(): Toggle row selection
The grid uses inline styles for simplicity and portability. All styles are contained within the component and can be easily customized:
// Example customization
const gridStyles = {
container: {
backgroundColor: '#f8fafc',
padding: '24px',
},
header: {
fontSize: '24px',
fontWeight: 'bold',
color: '#1e293b',
},
// ... more styles
};The grid expects data in the following format:
const data = [
{
id: 1,
name: 'John Doe',
department: 'Engineering',
age: 28,
salary: 75000,
status: 'Active'
},
// ... more records
];Supports common validation rules:
{
required: true, // Field is required
min: 18, // Minimum value (for numbers)
max: 65, // Maximum value (for numbers)
}- Node.js 14+
- React 17+
- Modern web browser
# Clone the repository
git clone <repository-url>
cd syncfusion-datagrid
# Install dependencies
npm install
# Start development server
npm startnpm start: Run development servernpm test: Run testsnpm run build: Build for productionnpm run eject: Eject from Create React App
- Chrome 90+
- Firefox 88+
- Safari 14+
- Edge 90+
The grid is optimized for performance with:
- React.memo for expensive calculations
- useMemo for derived state
- Efficient filtering and sorting algorithms
- Virtual scrolling ready architecture
| Feature | Syncfusion Grid | Custom Grid |
|---|---|---|
| Dependencies | Heavy (~2MB) | None |
| Customization | Limited | Full control |
| Bundle Size | Large | Minimal |
| Performance | Good | Excellent |
| Learning Curve | Steep | Gentle |
| Cost | Commercial | Free |
- Column resizing
- Export to CSV/Excel
- Advanced filtering
- Row grouping
- Drag-and-drop rows
- Cell merging
- Infinite scrolling
- Accessibility features
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
This project is licensed under the MIT License - see the LICENSE file for details.
For questions, issues, or contributions, please open an issue on GitHub.