# swimlane/ngx-datatable architecture

> Architecture diagram of the GitHub repository swimlane/ngx-datatable, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-01-25). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/swimlane/ngx-datatable
- Repository: https://github.com/swimlane/ngx-datatable

## Overview

##### Project Type Analysis
This is an Angular component library specifically focused on creating a feature-rich data table component. It's a standalone UI component that can be integrated into any Angular application.

##### Main Architectural Components

Core Components Layer:
- DatatableComponent (Main container)
- Body Components (BodyComponent, BodyRowComponent, BodyCellComponent)
- Header Components (HeaderComponent, HeaderCellComponent)
- Footer Components (FooterComponent, PagerComponent)
- Row Detail Components
- Column Components

Service Layer:
- ColumnChangesService
- DimensionsHelperService
- ScrollbarHelperService

Utility Layer:
- Column Helpers
- Math Utils
- Selection Utils
- Sort Utils
- Tree Utils

Feature Modules:
- Selection Module
- Sorting Module
- Pagination Module
- Row Grouping Module
- Column Management Module

**┌─────────────────────────────────────────────┐**
- Public API Layer               │
- ┤
- Core Components Layer            │
- ┤
- Services Layer                 │
- ┤
- Utilities Layer                │
- ┘

##### Key Elements to Highlight

Virtual DOM Implementation:
**┌─────────────────┐         ┌──────────────┐**
- Virtual Scroll │ ──────> │ Rendered Rows│
- ┘         └──────────────┘

Data Flow:
**┌──────────┐     ┌──────────┐     ┌──────────┐**
- Input   │ --> │  Table   │ --> │ Rendered │
- Data   │     │  State   │     │   View   │
- ┘     └──────────┘     └──────────┘

##### Integration Points
- How the library integrates with parent Angular applications
- Theming system integration points
- Server-side integration points for pagination/sorting

**┌─────────────────┐    ┌────────────────┐**
- Virtual Scroll  │ -> │ Row Recycling  │
- ┘    └────────────────┘

**┌────────────────┐    ┌────────────────┐**
- Cell Templates │    │ Header/Footer  │
- > │   Templates    │
- ┘    └────────────────┘

##### Implementation Details

Directives:
- DraggableDirective
- ResizeableDirective
- OrderableDirective
- LongPressDirective

Theme management:
**┌────────────────┐    ┌────────────────┐**
- Theme Service  │ -> │ Style Injection│
- ┘    └────────────────┘

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Public_API
        API[NGX-Datatable Public API]
    end

    subgraph Core_Components
        DT["DatatableComponent"]:::core
        
        subgraph Body
            BC["BodyComponent"]:::core
            BCL["BodyCellComponent"]:::core
            BR["BodyRowComponent"]:::core
        end
        
        subgraph Header
            HC["HeaderComponent"]:::core
            HCL["HeaderCellComponent"]:::core
        end
        
        subgraph Footer
            FC["FooterComponent"]:::core
            PC["PagerComponent"]:::core
        end
        
        RD["Row Detail"]:::core
        CD["Column"]:::core
    end

    subgraph Services
        CCS["ColumnChangesService"]:::service
        DHS["DimensionsHelperService"]:::service
        SHS["ScrollbarHelperService"]:::service
    end

    subgraph Utils
        CU["Column Utils"]:::util
        MU["Math Utils"]:::util
        SEU["Selection Utils"]:::util
        SU["Sort Utils"]:::util
        TU["Tree Utils"]:::util
    end

    subgraph Feature_Directives
        DD["DraggableDirective"]:::feature
        RSD["ResizeableDirective"]:::feature
        OD["OrderableDirective"]:::feature
        LP["LongPressDirective"]:::feature
    end

    subgraph Theme_Management
        TH["Theme System"]:::theme
    end

    %% Relationships
    API --> DT
    DT --> BC
    DT --> HC
    DT --> FC
    DT --> RD
    DT --> CD
    
    BC --> BCL
    BC --> BR
    HC --> HCL
    FC --> PC

    DT --> CCS
    DT --> DHS
    DT --> SHS

    BC --> CU
    BC --> MU
    BC --> SEU
    HC --> SU
    RD --> TU

    CD --> DD
    CD --> RSD
    CD --> OD
    BC --> LP

    DT --> TH

    %% Click Events
    click DT "https://github.com/swimlane/ngx-datatable/blob/master/projects/swimlane/ngx-datatable/src/lib/components/datatable.component.ts"
    click BC "https://github.com/swimlane/ngx-datatable/blob/master/projects/swimlane/ngx-datatable/src/lib/components/body/body.component.ts"
    click BCL "https://github.com/swimlane/ngx-datatable/blob/master/projects/swimlane/ngx-datatable/src/lib/components/body/body-cell.component.ts"
    click BR "https://github.com/swimlane/ngx-datatable/blob/master/projects/swimlane/ngx-datatable/src/lib/components/body/body-row.component.ts"
    click HC "https://github.com/swimlane/ngx-datatable/blob/master/projects/swimlane/ngx-datatable/src/lib/components/header/header.component.ts"
    click HCL "https://github.com/swimlane/ngx-datatable/blob/master/projects/swimlane/ngx-datatable/src/lib/components/header/header-cell.component.ts"
    click FC "https://github.com/swimlane/ngx-datatable/blob/master/projects/swimlane/ngx-datatable/src/lib/components/footer/footer.component.ts"
    click PC "https://github.com/swimlane/ngx-datatable/blob/master/projects/swimlane/ngx-datatable/src/lib/components/footer/pager.component.ts"
    click RD "https://github.com/swimlane/ngx-datatable/blob/master/projects/swimlane/ngx-datatable/src/lib/components/row-detail/row-detail.directive.ts"
    click CD "https://github.com/swimlane/ngx-datatable/blob/master/projects/swimlane/ngx-datatable/src/lib/components/columns/column.directive.ts"
    click CCS "https://github.com/swimlane/ngx-datatable/blob/master/projects/swimlane/ngx-datatable/src/lib/services/column-changes.service.ts"
    click DHS "https://github.com/swimlane/ngx-datatable/blob/master/projects/swimlane/ngx-datatable/src/lib/services/dimensions-helper.service.ts"
    click SHS "https://github.com/swimlane/ngx-datatable/blob/master/projects/swimlane/ngx-datatable/src/lib/services/scrollbar-helper.service.ts"
    click CU "https://github.com/swimlane/ngx-datatable/blob/master/projects/swimlane/ngx-datatable/src/lib/utils/column.ts"
    click MU "https://github.com/swimlane/ngx-datatable/blob/master/projects/swimlane/ngx-datatable/src/lib/utils/math.ts"
    click SEU "https://github.com/swimlane/ngx-datatable/blob/master/projects/swimlane/ngx-datatable/src/lib/utils/selection.ts"
    click SU "https://github.com/swimlane/ngx-datatable/blob/master/projects/swimlane/ngx-datatable/src/lib/utils/sort.ts"
    click TU "https://github.com/swimlane/ngx-datatable/blob/master/projects/swimlane/ngx-datatable/src/lib/utils/tree.ts"
    click DD "https://github.com/swimlane/ngx-datatable/blob/master/projects/swimlane/ngx-datatable/src/lib/directives/draggable.directive.ts"
    click RSD "https://github.com/swimlane/ngx-datatable/blob/master/projects/swimlane/ngx-datatable/src/lib/directives/resizeable.directive.ts"
    click OD "https://github.com/swimlane/ngx-datatable/blob/master/projects/swimlane/ngx-datatable/src/lib/directives/orderable.directive.ts"
    click LP "https://github.com/swimlane/ngx-datatable/blob/master/projects/swimlane/ngx-datatable/src/lib/directives/long-press.directive.ts"
    click TH "https://github.com/swimlane/ngx-datatable/tree/master/projects/swimlane/ngx-datatable/src/lib/themes/"

    %% Styles
    classDef core fill:#2196F3,stroke:#1565C0,color:white
    classDef service fill:#4CAF50,stroke:#2E7D32,color:white
    classDef util fill:#FFC107,stroke:#FFA000,color:black
    classDef feature fill:#9C27B0,stroke:#7B1FA2,color:white
    classDef theme fill:#607D8B,stroke:#455A64,color:white

    %% Legend
    subgraph Legend
        L1["Core Component"]:::core
        L2["Service"]:::service
        L3["Utility"]:::util
        L4["Feature"]:::feature
        L5["Theme"]:::theme
    end
```
