CxJS

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 JohnsonNorth AmericaChrome97
Bob SmithEuropeFirefox8
Carol WhiteAsiaSafari11
David BrownSouth AmericaEdge80
Eva GreenAfricaOpera100
Alice JohnsonNorth AmericaChrome60
Bob SmithEuropeFirefox72
Carol WhiteAsiaSafari18
David BrownSouth AmericaEdge50
Eva GreenAfricaOpera34
Alice JohnsonNorth AmericaChrome78
Bob SmithEuropeFirefox77
Carol WhiteAsiaSafari44
David BrownSouth AmericaEdge47
Eva GreenAfricaOpera20
Alice JohnsonNorth AmericaChrome95
Bob SmithEuropeFirefox40
Carol WhiteAsiaSafari30
David BrownSouth AmericaEdge1
Eva GreenAfricaOpera53
Alice JohnsonNorth AmericaChrome23
Bob SmithEuropeFirefox62
Carol WhiteAsiaSafari28
David BrownSouth AmericaEdge24
Eva GreenAfricaOpera66
Alice JohnsonNorth AmericaChrome20
Bob SmithEuropeFirefox29
Carol WhiteAsiaSafari96
David BrownSouth AmericaEdge29
Eva GreenAfricaOpera63
Alice JohnsonNorth AmericaChrome48
Bob SmithEuropeFirefox49
Carol WhiteAsiaSafari98
David BrownSouth AmericaEdge73
Eva GreenAfricaOpera46
Alice JohnsonNorth AmericaChrome13
Bob SmithEuropeFirefox27
Carol WhiteAsiaSafari56
David BrownSouth AmericaEdge92
Eva GreenAfricaOpera62
Alice JohnsonNorth AmericaChrome34
Bob SmithEuropeFirefox56
Carol WhiteAsiaSafari96
David BrownSouth AmericaEdge37
Eva GreenAfricaOpera87
Alice JohnsonNorth AmericaChrome14
Bob SmithEuropeFirefox69
Carol WhiteAsiaSafari63
David BrownSouth AmericaEdge8
Eva GreenAfricaOpera25
Alice JohnsonNorth AmericaChrome3
Bob SmithEuropeFirefox50
Carol WhiteAsiaSafari83
David BrownSouth AmericaEdge95
Eva GreenAfricaOpera32
Alice JohnsonNorth AmericaChrome88
Bob SmithEuropeFirefox73
Carol WhiteAsiaSafari96
David BrownSouth AmericaEdge44
Eva GreenAfricaOpera36

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 CSS table-layout: fixed for faster rendering
  • mod="contain" - Adds CSS containment for better browser optimization
  • cached - 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

PropertyTypeDescription
bufferedbooleanEnables buffered rendering mode.
bufferSizenumberNumber of rows to render outside the visible area. Default is 60.
bufferStepnumberNumber of rows to add/remove when scrolling. Default is 15.
cachedbooleanPrevents row re-renders when unrelated store data changes. Rows only update when their record data changes.
lockColumnWidthsbooleanLocks column widths to prevent layout shifts during scrolling.
lockColumnWidthsRequiredRowCountnumberMinimum number of rows required before column widths are locked.
measureRowsOnScrollbooleanRe-measures row heights while scrolling. Useful for variable height rows.

See also: Infinite Scrolling