Skip to content

About

πŸš€ Powerful React data grid built from scratch. Sort, filter, edit, paginate with zero dependencies. Complete alternative to expensive commercial libraries with comprehensive documentation and junior developer tutorials.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

Β 

History

2 Commits

Folders and files

Repository files navigation

Custom Data Grid Component

A fully functional, dependency-free data grid built with React that replicates Syncfusion Grid functionality without external libraries.

Overview

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.

Features

Core Functionality

  • 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

Advanced Features

  • 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

Component Structure

src/
components/
  CustomDataGrid.jsx    # Main grid component
  DataGrid.jsx          # Original Syncfusion version (for comparison)
App.tsx                 # Application entry point

Usage

Basic Implementation

import React from 'react';
import CustomDataGrid from './components/CustomDataGrid';

function App() {
  return (
    <div className="App">
      <CustomDataGrid />
    </div>
  );
}

Column Configuration

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' 
  }
];

Custom Templates

// 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>
);

API Reference

Props

The CustomDataGrid component is self-contained and doesn't require any props. All data and configuration are handled internally.

State Management

The component uses React hooks for state management:

  • data: Master dataset
  • filteredData: Filtered dataset
  • currentPage: Current page number
  • pageSize: Number of items per page
  • sortConfig: Current sorting configuration
  • filters: Column-specific filters
  • editingCell: Currently editing cell
  • searchTerm: Global search term
  • selectedRows: Selected row IDs

Event Handlers

  • handleSort(): Column sorting
  • handleFilter(): Column filtering
  • handleCellEdit(): Start cell editing
  • saveCellEdit(): Save edited cell
  • handleDelete(): Delete row
  • handleAdd(): Add new row
  • handleRowSelect(): Toggle row selection

Styling

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
};

Data Format

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
];

Validation Rules

Supports common validation rules:

{
  required: true,        // Field is required
  min: 18,              // Minimum value (for numbers)
  max: 65,              // Maximum value (for numbers)
}

Getting Started

Prerequisites

  • Node.js 14+
  • React 17+
  • Modern web browser

Installation

# Clone the repository
git clone <repository-url>
cd syncfusion-datagrid

# Install dependencies
npm install

# Start development server
npm start

Available Scripts

  • npm start: Run development server
  • npm test: Run tests
  • npm run build: Build for production
  • npm run eject: Eject from Create React App

Browser Support

  • Chrome 90+
  • Firefox 88+
  • Safari 14+
  • Edge 90+

Performance

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

Comparison with Syncfusion

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

Future Enhancements

  • Column resizing
  • Export to CSV/Excel
  • Advanced filtering
  • Row grouping
  • Drag-and-drop rows
  • Cell merging
  • Infinite scrolling
  • Accessibility features

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests if applicable
  5. Submit a pull request

License

This project is licensed under the MIT License - see the LICENSE file for details.

Support

For questions, issues, or contributions, please open an issue on GitHub.

About

πŸš€ Powerful React data grid built from scratch. Sort, filter, edit, paginate with zero dependencies. Complete alternative to expensive commercial libraries with comprehensive documentation and junior developer tutorials.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages