DataGrid Components
Two approaches to building data grids: a lightweight self-contained version and a production-ready wrapper around SVAR Grid
Database Connected
100
Total Employees
Β£77,080
Average Salary
7
Departments
Component Comparison
DataGridBasic
- β Zero dependencies
- β Copy-paste ready
- β ~10KB bundle size
- β Column sorting
- β Global search
- β Pagination
- β No virtual scrolling
- β No inline editing
- β Basic filtering only
Best for: Small-medium datasets (up to 500 rows), prototypes, learning
DataGridAdvanced
- β Virtual scrolling
- β Global search
- β Column sorting
- β Inline editing
- β Row selection
- β Bulk operations
- β CSV export
- β Theme support
- β Requires SVAR Grid
- β ~155KB bundle
- β Not copy-paste ready
Best for: Large datasets (1000s of rows), production apps, rich features
Live Examples
Currency Format Comparison - Choose Your Format
The same salary data displayed in three different formats. You choose which formatter to use for each column!
Three Currency Formatters Available:
formatCurrency- Standard with commas, no decimals (e.g., Β£75,000)formatCurrencyDecimals- With commas AND decimals (e.g., Β£75,000.00)formatCurrencyCompact- With K/M abbreviations (e.g., Β£75K)
Each column below uses a different formatter on the same salary data. You can use different formats in different columns based on your needs!
| First Name | Last Name | Standard (No Decimals) | With Decimals | Compact (K/M) |
|---|---|---|---|---|
| Grace | Allen | Β£62,000 | Β£62,000.00 | Β£62K |
| Laura | Anderson | Β£70,000 | Β£70,000.00 | Β£70K |
| Maya | Angelou | Β£66,000 | Β£66,000.00 | Β£66K |
| Neil | Armstrong | Β£105,000 | Β£105,000.00 | Β£105K |
| Eve | Arnold | Β£80,000 | Β£80,000.00 | Β£80K |
| Felix | Baumgartner | Β£73,000 | Β£73,000.00 | Β£73K |
| Xander | Berkeley | Β£73,000 | Β£73,000.00 | Β£73K |
| Zach | Braff | Β£75,000 | Β£75,000.00 | Β£75K |
| Emily | Brown | Β£72,000 | Β£72,000.00 | Β£72K |
| Ursula | Burns | Β£80,000 | Β£80,000.00 | Β£80K |
Showing 1β10 of
100
How to Use Different Formatters:
import { formatCurrency, formatCurrencyDecimals, formatCurrencyCompact } from '$lib/dataGridFormatters';
const columns: DataGridColumn[] = [
{
id: 'annualBudget',
header: 'Annual Budget',
formatter: formatCurrencyCompact // β Use compact for large numbers (Β£1.5M)
},
{
id: 'productPrice',
header: 'Product Price',
formatter: formatCurrencyDecimals // β Use decimals for precise prices (Β£12.99)
},
{
id: 'totalRevenue',
header: 'Total Revenue',
formatter: formatCurrency // β Use standard for whole numbers (Β£75,000)
}
];Usage Guide
Column Styling & Formatting
<script>
import DataGridBasic from '$lib/components/DataGridBasic.svelte';
import {
formatCurrencyCompact,
createGradientStyle,
createStatusBadge,
createIconRenderer
} from '$lib/dataGridFormatters';
const columns = [
{
id: 'salary',
header: 'Salary',
type: 'number',
formatter: formatCurrencyCompact, // Β£75K, Β£1.5M
cellStyle: createGradientStyle(30000, 150000, '#ef4444', '#22c55e')
},
{
id: 'status',
header: 'Status',
cellRenderer: createStatusBadge({
'active': { color: '#22c55e', label: 'Active' },
'on-leave': { color: '#f59e0b', label: 'On Leave' }
})
},
{
id: 'performance',
header: 'Level',
cellRenderer: createIconRenderer([
{ max: 50000, icon: 'π', color: '#ef4444' },
{ max: 100000, icon: 'π', color: '#3b82f6' },
{ max: Infinity, icon: 'π', color: '#22c55e' }
])
}
];
</script>
<DataGridBasic { data } { columns } />DataGridBasic - Copy & Paste Ready
<script>
import DataGridBasic from '$lib/components/DataGridBasic.svelte';
const columns = [
{ id: 'name', header: 'Name', width: 150 },
{ id: 'email', header: 'Email', type: 'email' },
{
id: 'salary',
header: 'Salary',
type: 'number',
formatter: (val) => `Β£${val.toLocaleString()}`
}
];
const data = [
{ name: 'John Doe', email: 'john@example.com', salary: 75000 },
// ... more rows
];
</script>
<DataGridBasic
{ data }
{ columns }
sortable={ true }
filterable={ true }
pageSize={ 10 }
/>DataGridAdvanced - Production Features
<script>
import DataGridAdvanced from '$lib/components/DataGridAdvanced.svelte';
// Auto-generates columns from data structure
const employees = []; // Your employee data
</script>
<DataGridAdvanced
data={ employees }
editable={ true }
selectable={ true }
exportable={ true }
pageSize={ 20 }
theme="willow"
/>DataGridFilters - Advanced Filtering
<script>
import DataGridFilters from '$lib/components/DataGridFilters.svelte';
import DataGridAdvanced from '$lib/components/DataGridAdvanced.svelte';
let filters = $state({
departments: [],
statuses: [],
salaryMin: 30000,
salaryMax: 150000,
hireDateFrom: '',
hireDateTo: ''
});
const filteredData = $derived.by(() => {
return data.filter(employee => {
// Apply filter logic
return true;
});
});
</script>
<DataGridFilters
departments={ ['Engineering', 'Sales', 'Marketing'] }
statuses={ ['active', 'on-leave'] }
salaryRange={ { min: 30000, max: 150000 } }
onFiltersChange={ (newFilters) => filters = newFilters }
/>
<DataGridAdvanced
data={ filteredData }
editable={ false }
selectable={ false }
pageSize={ 20 }
exportable={ true }
/>Department Breakdown
Engineering
31 employees
Sales
19 employees
Marketing
14 employees
Design
12 employees
Finance
10 employees
Customer Success
7 employees
HR
7 employees