Buffering
import { Grid } from 'cx/widgets'; Copied Grid supports buffered rendering which dramatically improves performance with large datasets. Instead of rendering all rows, only visible rows plus a buffer are rendered, enabling smooth scrolling with thousands of records.
<div controller={PageController}>
<Grid
records={m.records}
keyField="id"
buffered
style="height: 400px"
mod={["fixed-layout", "contain"]}
cached
selection={{ type: KeySelection, bind: m.selection }}
columns={[
{
header: "#",
align: "center",
children: <div class="cxe-grid-row-number" />,
defaultWidth: 70,
},
{
header: { text: "Name", style: "width: 100%" },
field: "fullName",
sortable: true,
resizable: true,
},
{
header: "Continent",
field: "continent",
sortable: true,
resizable: true,
defaultWidth: 130,
},
{
header: "Browser",
field: "browser",
sortable: true,
resizable: true,
defaultWidth: 100,
},
{
header: "Visits",
field: "visits",
sortable: true,
align: "right",
resizable: true,
defaultWidth: 70,
},
]}
/>
</div> | # | Name | Continent | Browser | Visits |
|---|---|---|---|---|
| Alice Johnson | North America | Chrome | 97 | |
| Bob Smith | Europe | Firefox | 8 | |
| Carol White | Asia | Safari | 11 | |
| David Brown | South America | Edge | 80 | |
| Eva Green | Africa | Opera | 100 | |
| Alice Johnson | North America | Chrome | 60 | |
| Bob Smith | Europe | Firefox | 72 | |
| Carol White | Asia | Safari | 18 | |
| David Brown | South America | Edge | 50 | |
| Eva Green | Africa | Opera | 34 | |
| Alice Johnson | North America | Chrome | 78 | |
| Bob Smith | Europe | Firefox | 77 | |
| Carol White | Asia | Safari | 44 | |
| David Brown | South America | Edge | 47 | |
| Eva Green | Africa | Opera | 20 | |
| Alice Johnson | North America | Chrome | 95 | |
| Bob Smith | Europe | Firefox | 40 | |
| Carol White | Asia | Safari | 30 | |
| David Brown | South America | Edge | 1 | |
| Eva Green | Africa | Opera | 53 | |
| Alice Johnson | North America | Chrome | 23 | |
| Bob Smith | Europe | Firefox | 62 | |
| Carol White | Asia | Safari | 28 | |
| David Brown | South America | Edge | 24 | |
| Eva Green | Africa | Opera | 66 | |
| Alice Johnson | North America | Chrome | 20 | |
| Bob Smith | Europe | Firefox | 29 | |
| Carol White | Asia | Safari | 96 | |
| David Brown | South America | Edge | 29 | |
| Eva Green | Africa | Opera | 63 | |
| Alice Johnson | North America | Chrome | 48 | |
| Bob Smith | Europe | Firefox | 49 | |
| Carol White | Asia | Safari | 98 | |
| David Brown | South America | Edge | 73 | |
| Eva Green | Africa | Opera | 46 | |
| Alice Johnson | North America | Chrome | 13 | |
| Bob Smith | Europe | Firefox | 27 | |
| Carol White | Asia | Safari | 56 | |
| David Brown | South America | Edge | 92 | |
| Eva Green | Africa | Opera | 62 | |
| Alice Johnson | North America | Chrome | 34 | |
| Bob Smith | Europe | Firefox | 56 | |
| Carol White | Asia | Safari | 96 | |
| David Brown | South America | Edge | 37 | |
| Eva Green | Africa | Opera | 87 | |
| Alice Johnson | North America | Chrome | 14 | |
| Bob Smith | Europe | Firefox | 69 | |
| Carol White | Asia | Safari | 63 | |
| David Brown | South America | Edge | 8 | |
| Eva Green | Africa | Opera | 25 | |
| Alice Johnson | North America | Chrome | 3 | |
| Bob Smith | Europe | Firefox | 50 | |
| Carol White | Asia | Safari | 83 | |
| David Brown | South America | Edge | 95 | |
| Eva Green | Africa | Opera | 32 | |
| Alice Johnson | North America | Chrome | 88 | |
| Bob Smith | Europe | Firefox | 73 | |
| Carol White | Asia | Safari | 96 | |
| David Brown | South America | Edge | 44 | |
| Eva Green | Africa | Opera | 36 |
This grid contains 5,000 rows but renders smoothly thanks to buffered mode. Try scrolling and sorting to see the performance.
How It Works
Enable buffered mode by setting the buffered property. The grid calculates which rows are visible and renders only those plus a configurable buffer for smooth scrolling.
<Grid
records={m.records}
buffered
style="height: 400px"
mod={["fixed-layout", "contain"]}
cached
columns={columns}
/>
For optimal performance, combine buffering with:
- Fixed height - The grid needs a fixed height to calculate visible rows
mod="fixed-layout"- Uses CSStable-layout: fixedfor faster renderingmod="contain"- Adds CSS containment for better browser optimizationcached- Prevents row re-renders when unrelated store data changes
Row Numbers
Use the built-in cxe-grid-row-number class to display automatic row numbers:
{
header: "#",
defaultWidth: 50,
children: <div class="cxe-grid-row-number" />
}
Configuration
| Property | Type | Description |
|---|---|---|
buffered | boolean | Enables buffered rendering mode. |
bufferSize | number | Number of rows to render outside the visible area. Default is 60. |
bufferStep | number | Number of rows to add/remove when scrolling. Default is 15. |
cached | boolean | Prevents row re-renders when unrelated store data changes. Rows only update when their record data changes. |
lockColumnWidths | boolean | Locks column widths to prevent layout shifts during scrolling. |
lockColumnWidthsRequiredRowCount | number | Minimum number of rows required before column widths are locked. |
measureRowsOnScroll | boolean | Re-measures row heights while scrolling. Useful for variable height rows. |
See also: Infinite Scrolling