Skip to content

External vertical scroll (verticalScroll: 'external') ​

Added in 1.7.2

With the default ('own') nothing changes.

By default the grid has its own vertical scroll area. With verticalScroll: 'external' the grid creates no vertical scroll area, and a scroll area outside it (the host) does the scrolling. It exists so that a grid and a Gantt chart placed side by side move as one block, and createSplitView uses it for you. You only need the API below when you build your own host.

Option ​

OptionTypeDefaultDescription
verticalScroll'own' | 'external''own'With 'external' no vertical scroll area is created. The body becomes a fixed-height window, and the host tells the grid which rows are visible with api.external.setViewport

In 'external' the grid root (.mxg) has the class mxg-external and clips vertical overflow. The header stays fixed at the top, and the horizontal scrollbar stays at the bottom of the grid. The outer border is drawn by the host (the split card), so the grid's own border is removed.

API ​

api.external is the entry point when verticalScroll is 'external'.

NameDescription
api.external.setViewport({ scrollTop, height })Tells the grid the host scroll area's position (scrollTop, px) and visible height (height, px). Call it on every scroll and resize. The grid draws the row range for that value
api.external.onRequest(cb)Calls cb(scrollTop) when the grid wants another position: scrolling to a row (scrollToRow), a cell focus leaving the screen (ensureVisible), Ctrl+Home, Ctrl+End, PageUp, PageDown, and edge auto-scroll while dragging. The host applies the value to its own scroll area. Returns an unsubscribe function
ts
const grid = createGrid(el, {
  columns,
  rows,
  rowKey: 'id',
  rowHeight: 32,
  verticalScroll: 'external',
});

// Connect the host's vertical scroll area (scroller) to the grid.
const sync = () =>
  grid.external.setViewport({ scrollTop: scroller.scrollTop, height: scroller.clientHeight });
scroller.addEventListener('scroll', sync, { passive: true });
new ResizeObserver(sync).observe(scroller);
const off = grid.external.onRequest((top) => {
  scroller.scrollTop = top;
});
sync();
  • getScroll().top is the position the grid draws. Unless the height was compressed for a very large row count it is the scrollTop given to setViewport; when compressed it is the position in the full content, converted by toVirtual.
  • With very many rows, take the spacer height from spacerHeight() and convert positions with toVirtual and toDom (the grid and the chart use the same rule, so one million rows reach the bottom).
  • 'external' works only when every row has the same height. With rowHeight: 'auto' or a function, rowsResizable, detail, bodyLayout or autoGridHeight the option check rejects it.
  • Keep the scroll area out of the tab order; the grid stays focusable. aria-rowcount and aria-rowindex are unchanged.
  • For an exact line match, apply the same scroll value to both panes and use an integer row height (px).

Gantt chart ​

The chart works the same way: createGantt(el, { verticalScroll: 'external' }), and gantt.external offers the same calls (setViewport, onRequest, spacerHeight, onSpacerChange, toVirtual, toDom). When you connect the grid and the chart with createSplitView and attachGrid you do not call it yourself. Details are in Grid sync in the Gantt guide and Grid and chart in one scroll.