|
| 1 | +# AG Grid Migration Guide |
| 2 | + |
| 3 | +## Overview |
| 4 | + |
| 5 | +We have successfully migrated from TanStack Table to AG Grid (v35.0.0) for the frontend table component. AG Grid provides enterprise-grade features with better performance and more comprehensive functionality out of the box. |
| 6 | + |
| 7 | +## What Changed |
| 8 | + |
| 9 | +### Before (TanStack Table) |
| 10 | +- Manual implementation of pagination, sorting, filtering |
| 11 | +- Custom drag-and-drop with @dnd-kit libraries |
| 12 | +- Limited built-in features |
| 13 | +- More boilerplate code required |
| 14 | + |
| 15 | +### After (AG Grid) |
| 16 | +- Built-in pagination, sorting, filtering |
| 17 | +- Native row dragging and column resizing |
| 18 | +- Advanced features like row grouping, aggregation (available in enterprise version) |
| 19 | +- Less code, more features |
| 20 | + |
| 21 | +## Features Implemented |
| 22 | + |
| 23 | +### ✅ Core Features |
| 24 | + |
| 25 | +1. **Row Selection** |
| 26 | + - Checkbox-based multi-row selection |
| 27 | + - Header checkbox for select all/deselect all |
| 28 | + - Custom checkbox renderer using our UI components |
| 29 | + |
| 30 | +2. **Sorting** |
| 31 | + - Click column headers to sort |
| 32 | + - Multi-column sorting support |
| 33 | + - Custom sort indicators |
| 34 | + |
| 35 | +3. **Filtering** |
| 36 | + - Built-in column filters |
| 37 | + - Quick filter (search across all columns) |
| 38 | + - Custom filter UI integration |
| 39 | + |
| 40 | +4. **Pagination** |
| 41 | + - Custom pagination controls (hidden AG Grid default) |
| 42 | + - Configurable page sizes (10, 20, 30, 40, 50) |
| 43 | + - First/Previous/Next/Last navigation |
| 44 | + |
| 45 | +5. **Drag and Drop** |
| 46 | + - Row reordering via drag handle |
| 47 | + - Visual feedback during drag |
| 48 | + - Managed by AG Grid internally |
| 49 | + |
| 50 | +6. **Column Management** |
| 51 | + - Column visibility toggle |
| 52 | + - Column resizing |
| 53 | + - Fixed column widths where needed |
| 54 | + |
| 55 | +7. **Custom Cell Renderers** |
| 56 | + - Status badges with icons |
| 57 | + - Editable input cells |
| 58 | + - Dropdown selectors |
| 59 | + - Action menus |
| 60 | + - Clickable links |
| 61 | + |
| 62 | +8. **Theme Integration** |
| 63 | + - Custom CSS theme matching ObjectOS design system |
| 64 | + - Dark mode support via `ag-theme-alpine-dark` |
| 65 | + - Tailwind CSS variable integration |
| 66 | + |
| 67 | +## Usage |
| 68 | + |
| 69 | +### Basic DataTable Component |
| 70 | + |
| 71 | +```tsx |
| 72 | +import { DataTable, schema } from '@objectos/ui'; |
| 73 | +import { z } from 'zod'; |
| 74 | + |
| 75 | +const sampleData: z.infer<typeof schema>[] = [ |
| 76 | + { |
| 77 | + id: 1, |
| 78 | + header: "Example", |
| 79 | + type: "Type", |
| 80 | + status: "Done", |
| 81 | + target: "10", |
| 82 | + limit: "15", |
| 83 | + reviewer: "John Doe", |
| 84 | + }, |
| 85 | + // ... more rows |
| 86 | +]; |
| 87 | + |
| 88 | +function MyComponent() { |
| 89 | + return <DataTable data={sampleData} />; |
| 90 | +} |
| 91 | +``` |
| 92 | + |
| 93 | +### Custom AG Grid Table |
| 94 | + |
| 95 | +```tsx |
| 96 | +import { AgGridTable } from '@objectos/ui'; |
| 97 | +// Use the same schema and data |
| 98 | +``` |
| 99 | + |
| 100 | +## File Structure |
| 101 | + |
| 102 | +``` |
| 103 | +packages/ui/src/ |
| 104 | +├── components/ |
| 105 | +│ ├── data-table.tsx # Main DataTable component (AG Grid) |
| 106 | +│ ├── ag-grid-table.tsx # Alternative export name |
| 107 | +│ └── data-table-old.tsx # Backup of TanStack implementation |
| 108 | +├── styles/ |
| 109 | +│ └── ag-grid-theme.css # Custom AG Grid theme |
| 110 | +└── styles.css # Imports AG Grid theme |
| 111 | +``` |
| 112 | + |
| 113 | +## Theme Customization |
| 114 | + |
| 115 | +The AG Grid theme is customized in `packages/ui/src/styles/ag-grid-theme.css` to match the ObjectOS design system: |
| 116 | + |
| 117 | +```css |
| 118 | +.ag-theme-alpine-dark { |
| 119 | + --ag-background-color: hsl(var(--background)); |
| 120 | + --ag-foreground-color: hsl(var(--foreground)); |
| 121 | + --ag-header-background-color: hsl(var(--muted)); |
| 122 | + /* ... more variables */ |
| 123 | +} |
| 124 | +``` |
| 125 | + |
| 126 | +## Advanced Features (Available) |
| 127 | + |
| 128 | +AG Grid v35 provides many advanced features that can be enabled: |
| 129 | + |
| 130 | +### 1. Server-Side Row Model |
| 131 | +For handling large datasets with server-side pagination, sorting, and filtering. |
| 132 | + |
| 133 | +### 2. Column Grouping |
| 134 | +Group related columns together with expandable headers. |
| 135 | + |
| 136 | +### 3. Row Grouping & Aggregation |
| 137 | +Group rows by column values and show aggregated data. |
| 138 | + |
| 139 | +### 4. Context Menu |
| 140 | +Custom right-click menu for rows and cells. |
| 141 | + |
| 142 | +### 5. Cell Editing |
| 143 | +Built-in editors for different data types. |
| 144 | + |
| 145 | +### 6. Export |
| 146 | +Export to CSV/Excel (enterprise feature). |
| 147 | + |
| 148 | +## Migration Checklist for Developers |
| 149 | + |
| 150 | +If you're updating a component to use AG Grid: |
| 151 | + |
| 152 | +- [ ] Replace TanStack Table imports with AG Grid imports |
| 153 | +- [ ] Convert column definitions to `ColDef[]` format |
| 154 | +- [ ] Update cell renderers to AG Grid's `ICellRendererParams` interface |
| 155 | +- [ ] Replace `useReactTable` hook with AG Grid's `AgGridReact` component |
| 156 | +- [ ] Update event handlers (e.g., `onRowClicked` → `onCellClicked`) |
| 157 | +- [ ] Remove @dnd-kit dependencies if only used for table drag-drop |
| 158 | +- [ ] Test pagination, sorting, and filtering |
| 159 | +- [ ] Verify theme matches design system |
| 160 | + |
| 161 | +## Performance Benefits |
| 162 | + |
| 163 | +1. **Virtual Scrolling**: Only renders visible rows |
| 164 | +2. **Efficient Updates**: Smart change detection |
| 165 | +3. **Optimized Filtering**: Built-in filter caching |
| 166 | +4. **Better Memory Management**: Recycles DOM nodes |
| 167 | + |
| 168 | +## Known Limitations |
| 169 | + |
| 170 | +1. **Bundle Size**: AG Grid adds ~500KB to the bundle (but removes @dnd-kit and TanStack Table) |
| 171 | +2. **Learning Curve**: Different API than TanStack Table |
| 172 | +3. **Enterprise Features**: Some features require AG Grid Enterprise license |
| 173 | + |
| 174 | +## Resources |
| 175 | + |
| 176 | +- [AG Grid Documentation](https://www.ag-grid.com/react-data-grid/) |
| 177 | +- [AG Grid v35 Release Notes](https://www.ag-grid.com/changelog/) |
| 178 | +- [Column Properties](https://www.ag-grid.com/react-data-grid/column-properties/) |
| 179 | +- [Cell Renderers](https://www.ag-grid.com/react-data-grid/component-cell-renderer/) |
| 180 | + |
| 181 | +## Support |
| 182 | + |
| 183 | +For questions or issues: |
| 184 | +1. Check AG Grid docs |
| 185 | +2. Review the implementation in `packages/ui/src/components/data-table.tsx` |
| 186 | +3. Create an issue in the ObjectOS repository |
0 commit comments