CxJS Docs

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 AmericaChrome66
Bob SmithEuropeFirefox99
Carol WhiteAsiaSafari37
David BrownSouth AmericaEdge59
Eva GreenAfricaOpera88
Alice JohnsonNorth AmericaChrome38
Bob SmithEuropeFirefox11
Carol WhiteAsiaSafari91
David BrownSouth AmericaEdge17
Eva GreenAfricaOpera61
Alice JohnsonNorth AmericaChrome29
Bob SmithEuropeFirefox41
Carol WhiteAsiaSafari59
David BrownSouth AmericaEdge72
Eva GreenAfricaOpera95
Alice JohnsonNorth AmericaChrome10
Bob SmithEuropeFirefox70
Carol WhiteAsiaSafari47
David BrownSouth AmericaEdge34
Eva GreenAfricaOpera79
Alice JohnsonNorth AmericaChrome32
Bob SmithEuropeFirefox65
Carol WhiteAsiaSafari60
David BrownSouth AmericaEdge45
Eva GreenAfricaOpera96
Alice JohnsonNorth AmericaChrome52
Bob SmithEuropeFirefox85
Carol WhiteAsiaSafari59
David BrownSouth AmericaEdge28
Eva GreenAfricaOpera22
Alice JohnsonNorth AmericaChrome55
Bob SmithEuropeFirefox23
Carol WhiteAsiaSafari77
David BrownSouth AmericaEdge31
Eva GreenAfricaOpera95
Alice JohnsonNorth AmericaChrome27
Bob SmithEuropeFirefox73
Carol WhiteAsiaSafari35
David BrownSouth AmericaEdge22
Eva GreenAfricaOpera23
Alice JohnsonNorth AmericaChrome34
Bob SmithEuropeFirefox19
Carol WhiteAsiaSafari41
David BrownSouth AmericaEdge44
Eva GreenAfricaOpera71
Alice JohnsonNorth AmericaChrome89
Bob SmithEuropeFirefox9
Carol WhiteAsiaSafari89
David BrownSouth AmericaEdge19
Eva GreenAfricaOpera37
Alice JohnsonNorth AmericaChrome83
Bob SmithEuropeFirefox29
Carol WhiteAsiaSafari67
David BrownSouth AmericaEdge70
Eva GreenAfricaOpera62
Alice JohnsonNorth AmericaChrome91
Bob SmithEuropeFirefox20
Carol WhiteAsiaSafari47
David BrownSouth AmericaEdge86
Eva GreenAfricaOpera82

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