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 AmericaChrome56
Bob SmithEuropeFirefox62
Carol WhiteAsiaSafari8
David BrownSouth AmericaEdge49
Eva GreenAfricaOpera44
Alice JohnsonNorth AmericaChrome21
Bob SmithEuropeFirefox5
Carol WhiteAsiaSafari75
David BrownSouth AmericaEdge73
Eva GreenAfricaOpera70
Alice JohnsonNorth AmericaChrome94
Bob SmithEuropeFirefox51
Carol WhiteAsiaSafari73
David BrownSouth AmericaEdge59
Eva GreenAfricaOpera51
Alice JohnsonNorth AmericaChrome12
Bob SmithEuropeFirefox26
Carol WhiteAsiaSafari41
David BrownSouth AmericaEdge8
Eva GreenAfricaOpera19
Alice JohnsonNorth AmericaChrome17
Bob SmithEuropeFirefox5
Carol WhiteAsiaSafari24
David BrownSouth AmericaEdge82
Eva GreenAfricaOpera32
Alice JohnsonNorth AmericaChrome67
Bob SmithEuropeFirefox61
Carol WhiteAsiaSafari23
David BrownSouth AmericaEdge71
Eva GreenAfricaOpera5
Alice JohnsonNorth AmericaChrome69
Bob SmithEuropeFirefox28
Carol WhiteAsiaSafari53
David BrownSouth AmericaEdge69
Eva GreenAfricaOpera96
Alice JohnsonNorth AmericaChrome74
Bob SmithEuropeFirefox76
Carol WhiteAsiaSafari72
David BrownSouth AmericaEdge49
Eva GreenAfricaOpera31
Alice JohnsonNorth AmericaChrome3
Bob SmithEuropeFirefox69
Carol WhiteAsiaSafari30
David BrownSouth AmericaEdge85
Eva GreenAfricaOpera27
Alice JohnsonNorth AmericaChrome83
Bob SmithEuropeFirefox90
Carol WhiteAsiaSafari77
David BrownSouth AmericaEdge100
Eva GreenAfricaOpera55
Alice JohnsonNorth AmericaChrome42
Bob SmithEuropeFirefox13
Carol WhiteAsiaSafari79
David BrownSouth AmericaEdge83
Eva GreenAfricaOpera77
Alice JohnsonNorth AmericaChrome65
Bob SmithEuropeFirefox49
Carol WhiteAsiaSafari12
David BrownSouth AmericaEdge94
Eva GreenAfricaOpera27

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