Skip to content

Grid and chart in one scroll ​

createSplitView and attachGrid can put the grid and the chart in one card with one vertical scrollbar at the far right. Wheel, touch and keys over either pane move the same scroller, so row n of the grid and row n of the chart are always at the same place (checked to the device pixel at 100%, 125%, 150% and 200% zoom), and nothing has to be forwarded between two scrollers.

What you set ​

Create the grid and the chart with verticalScroll: 'external':

ts
const grid = createGrid(gridHost, {
  columns,
  rows,
  rowKey: 'id',
  rowHeight: 32,
  headerHeight: 48,
  verticalScroll: 'external',
});
const split = createSplitView({ container, left, right }); // left holds the grid element
const gantt = createGantt(right, { rowHeight: 32, verticalScroll: 'external' });
gantt.setData(data);
gantt.attachGrid(grid);
  • createSplitView builds the unified card (.mxg-split-unified > .mxg-su-scroller > spacer + sticky box with the left pane, the divider and the right pane) when the left pane holds a grid in external mode. The container needs a definite height. A grid that is not in external mode or a foreign grid keeps the two-scroller layout described in "Grid sync"; unified: false on createSplitView forces that layout. verticalScroll cannot be changed after the grid or chart is created.
  • attachGrid finds the unified card around the chart and drives both panes from the card's scroller. Selection, tree collapse and the row order (filter, sort, group) are kept in sync as before. With unified: false (or without the card) a grid in external mode is driven by your own code through the external APIs: attachGrid then syncs only selection, collapse and row order. The two-scroller sync exists only for grids that are not in external mode. Calling the function attachGrid returned detaches the link: the card's spacer is removed and both panes go back to their first row (nobody drives them any more); call setViewport yourself if you keep using them.
  • If the grid is in external mode but the chart is not, the grid follows the chart's own vertical scroll.

Rules of external mode ​

  • Every row has the same height (rowHeight, a whole number of px, the same in grid and chart; row n sits at n x rowHeight). verticalScroll: 'external' is rejected together with rowHeight: 'auto' or a function, rowsResizable, detail, bodyLayout and autoGridHeight.
  • The grid's header height equals the chart's header height (48 px by default).
  • The vertical wheel over the grid goes to the card's scroller (it is not turned into horizontal scrolling); the horizontal scroll bar of each pane stays at the bottom of that pane.
  • Up to a million rows: a browser cannot scroll an element taller than a few ten million pixels, so above 8,000,000 px the scroller's height is compressed and both panes map the scroll position the same way.

Without createSplitView (your own layout) ​

The grid and the chart expose the same host calls (grid.external, gantt.external): setViewport({ scrollTop }), onRequest(cb), spacerHeight(), onSpacerChange(cb), toVirtual(scrollTop), toDom(virtual). Put both in a position: sticky box inside your own scroller whose spacer is as tall as the larger spacerHeight(), call setViewport on both from one scroll event, and answer onRequest by setting scrollTop.

Narrow screens (phones) ​

When the container is narrower than narrowBelow (600 px by default in the unified layout), the grid pane starts at narrowInitial of the width (default 0.38) so the chart keeps room. It applies at the start and whenever the container crosses the 600 px line, and it keeps the width once the user has dragged the divider (a double click on the divider returns to the first width). The two-scroller layout defaults to narrowBelow: 0 (off). On touch screens the scrollbar is 18 px thick.

Viewing it on the example pages ​

The example preview card and the "Try it" window have a Full screen button, handy for a Gantt example on a phone or a small window. Esc closes it.

Styling ​

The card draws the only outer border. Tokens (all optional): --mxg-su-header (header height, set for you), --mxg-su-bar (scroll bar thickness, default 15px, 18px on touch screens), --mxg-su-radius, --mxg-su-ring, --mxg-su-scrollbar, --mxg-su-scrollbar-hover, --mxg-su-scrollbar-active. Colors follow the grid's --mxg-* tokens.