Virtual Scrolling
Virtual scrolling renders only visible rows, providing smooth performance even with thousands of rows.
Small Dataset (1,000 rows)
Virtual scrolling with 1,000 rows. Only visible rows are rendered for optimal performance. Scroll through the data to see smooth performance.
Large Dataset (10,000 rows)
Virtual scrolling with 10,000 rows. Even with a large dataset, performance remains smooth. Try sorting and filtering to see how virtual scrolling handles operations efficiently.
Virtual Scrolling with Sorting and Filtering
Virtual scrolling works seamlessly with sorting and filtering. Operations are performed on the full dataset, but only visible rows are rendered.
Basic Virtual Scrolling
Virtual scrolling with 5,000 rows. Only visible rows are rendered for optimal performance. Scroll through the data to see smooth performance.
Code
<script setup lang="ts">
import { ref } from 'vue'
import { PantanalGrid, type ColumnDef } from '@pantanal/grid'
const rows = ref(Array.from({ length: 5000 }, (_, i) => ({
id: i + 1,
name: `Product ${i + 1}`,
price: Math.round(Math.random() * 100000) / 100,
category: ['Electronics', 'Clothing', 'Accessories'][i % 3]
})))
const columns: ColumnDef[] = [
{ field: 'id', title: 'ID', width: 80, sortable: true },
{ field: 'name', title: 'Name', sortable: true, filterable: true },
{ field: 'price', title: 'Price', sortable: true, format: (v: number) => `$${v.toFixed(2)}` },
{ field: 'category', title: 'Category', filterable: true }
]
</script>
<template>
<PantanalGrid
:rows="rows"
:columns="columns"
key-field="id"
:virtual="true"
:height="420"
:row-height="44"
locale="en"
responsive="table"
/>
</template>How Virtual Scrolling Works
Virtual scrolling only renders the rows that are currently visible in the viewport, plus a small buffer above and below. This dramatically improves performance for large datasets.
Benefits
- Performance: Smooth scrolling even with 10,000+ rows
- Memory efficient: Only visible DOM elements are created
- Fast initial render: Grid appears instantly regardless of data size
- Works with all features: Sorting, filtering, and grouping work seamlessly
Configuration
Row Height
Set a fixed row height for optimal performance:
<PantanalGrid
:rows="rows"
:columns="columns"
key-field="id"
:virtual="true"
:row-height="44"
:height="400"
/>Dynamic Row Height
For variable row heights, omit row-height (performance may be slightly reduced):
<PantanalGrid
:rows="rows"
:columns="columns"
key-field="id"
:virtual="true"
:height="400"
/>When to Use Virtual Scrolling
- ✅ Large datasets: 1,000+ rows
- ✅ Performance critical: Need smooth scrolling
- ✅ Memory constrained: Limited device memory
- ❌ Small datasets: < 100 rows (overhead not worth it)
- ❌ Variable row heights: May cause layout shifts
Performance Tips
- Set row height: Fixed height improves performance
- Limit columns: Fewer columns = faster rendering
- Avoid complex templates: Simple cell templates perform better
- Use server-side: For very large datasets, combine with server-side mode
See Also
- Server-Side Mode - For extremely large datasets