스크롤만 맞추기Align only the scroll
alignGrids의 columns를 빈 배열로 주면 컬럼 폭·순서는 건드리지 않고 스크롤만 맞춰요. 컬럼이 서로 달라도 되고, scroll로 x, y, both, none 중 맞출 방향을 골라요.Pass an empty columns array to alignGrids and only the scroll is aligned; column widths and order stay independent, and the grids may have different columns. Use scroll to pick x, y, both or none.
코드Code
탭을 골라 코드를 복사하세요. 위 화면은 이 코드를 그대로 실행한 결과예요.Pick a tab and copy the code. The preview above runs exactly this code.
이 화면은 새 모양 옵션을 켠 모양이에요: density: 'spacious', iconStyle: 'soft', motion: true (코드에 없으면 기본 모양으로 보여요)This preview has the new-look options on: density: 'spacious', iconStyle: 'soft', motion: true (without them in your code you get the default look)
버튼을 누르면 이 예제의 코드가 StackBlitz나 CodeSandbox로 전송돼요. 누르기 전에는 아무것도 보내지 않아요.
<div id="app">
<div class="toolbar">
<select aria-label="맞출 방향" id="scroll">
<option value="x" selected>가로(x)</option>
<option value="y">세로(y)</option>
<option value="both">둘 다</option>
<option value="none">맞추지 않음(none)</option>
</select>
<button type="button" id="end">끝으로</button>
<button type="button" id="start">처음으로</button>
</div>
<div id="grid" style="height: 170px"></div>
</div>
<script type="module" src="./main.js"></script>import { createGrid } from 'maxgrid';
import { actions, options, setup } from './example';
const api = createGrid(document.getElementById('grid'), options);
setup(api, console.log);
document.getElementById('scroll').addEventListener('change', (event) => actions.scroll(api, event.target.value));
document.getElementById('end').addEventListener('click', () => actions.end(api));
document.getElementById('start').addEventListener('click', () => actions.start(api));// 두 그리드는 컬럼이 서로 달라요. 컬럼 폭·순서는 맞추지 않고(columns: []) 스크롤만 따라가게 해요.
const MONTHS = {
m1: '1월',
m2: '2월',
m3: '3월',
m4: '4월',
m5: '5월',
m6: '6월',
m7: '7월',
m8: '8월',
m9: '9월',
m10: '10월',
m11: '11월',
m12: '12월',
};
export const options = {
columns: [
{ id: 'name', title: '지점', width: 140, pinned: 'start' },
...Object.entries(MONTHS).map(([id, title]) => ({
id,
title,
kind: 'number',
width: 110,
align: 'end',
})),
],
rows: ['서울 지점', '부산 지점', '대구 지점'].map((name, r) => ({
id: r + 1,
name,
...Object.fromEntries(Object.keys(MONTHS).map((id, i) => [id, 100 + ((r * 37 + i * 53) % 90)])),
})),
rowKey: 'id',
};
let second = null;
let host = null;
let link = null;
let say = () => { };
function connect(api, scroll) {
link?.unlink();
link = second === null ? null : api.alignWith(second, { scroll, columns: [] });
say({ ko: `스크롤 맞춤: ${scroll}`, en: `Scroll alignment: ${scroll}` });
}
export function setup(api, log) {
say = log;
const first = document.getElementById('grid');
host = document.createElement('div');
host.style.cssText = 'height:150px;margin-top:10px';
if (first !== null)
first.after(host);
else
document.body.append(host);
second = MaxGrid.createGrid(host, {
columns: [
{ id: 'name', title: '항목', width: 120, pinned: 'start' },
...Object.keys(MONTHS).map((id) => ({
id,
title: '실적률',
kind: 'number',
width: 70,
align: 'end',
})),
],
rows: ['목표 대비', '전년 대비'].map((name, r) => ({
id: r + 1,
name,
...Object.fromEntries(Object.keys(MONTHS).map((id, i) => [id, 80 + ((r * 11 + i * 7) % 40)])),
})),
rowKey: 'id',
ariaLabel: '실적률 그리드',
});
const off = api.on('gridsUnaligned', () => log({ ko: '연결이 끊겼어요.', en: 'The link was removed.' }));
connect(api, 'x');
log({
ko: '위 그리드를 가로로 스크롤하면 아래 그리드가 같은 위치로 따라가요.',
en: 'Scroll the top grid sideways and the bottom grid follows to the same position.',
});
return () => {
off();
link?.unlink();
second?.destroy();
host?.remove();
second = null;
host = null;
link = null;
};
}
export const actions = {
// 맞출 방향을 바꿔요. none이면 두 그리드가 따로 움직여요.
scroll: (api, value) => connect(api, value === 'both' || value === 'none' || value === 'y' ? value : 'x'),
// 위 그리드를 끝까지 스크롤해요.
end: (api) => api.setScroll({ left: 100000 }),
start: (api) => api.setScroll({ left: 0 }),
};<!doctype html>
<html lang="ko">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>스크롤만 맞추기</title>
</head>
<body>
<div class="toolbar">
<select aria-label="맞출 방향" id="scroll">
<option value="x" selected>가로(x)</option>
<option value="y">세로(y)</option>
<option value="both">둘 다</option>
<option value="none">맞추지 않음(none)</option>
</select>
<button type="button" id="end">끝으로</button>
<button type="button" id="start">처음으로</button>
</div>
<div id="grid" style="height: 170px"></div>
<ul id="log" aria-live="polite"></ul>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script>
// 두 그리드는 컬럼이 서로 달라요. 컬럼 폭·순서는 맞추지 않고(columns: []) 스크롤만 따라가게 해요.
const MONTHS = {
m1: '1월',
m2: '2월',
m3: '3월',
m4: '4월',
m5: '5월',
m6: '6월',
m7: '7월',
m8: '8월',
m9: '9월',
m10: '10월',
m11: '11월',
m12: '12월',
};
const options = {
columns: [
{ id: 'name', title: '지점', width: 140, pinned: 'start' },
...Object.entries(MONTHS).map(([id, title]) => ({
id,
title,
kind: 'number',
width: 110,
align: 'end',
})),
],
rows: ['서울 지점', '부산 지점', '대구 지점'].map((name, r) => ({
id: r + 1,
name,
...Object.fromEntries(Object.keys(MONTHS).map((id, i) => [id, 100 + ((r * 37 + i * 53) % 90)])),
})),
rowKey: 'id',
};
let second = null;
let host = null;
let link = null;
let say = () => { };
function connect(api, scroll) {
link?.unlink();
link = second === null ? null : api.alignWith(second, { scroll, columns: [] });
say({ ko: `스크롤 맞춤: ${scroll}`, en: `Scroll alignment: ${scroll}` });
}
function setup(api, log) {
say = log;
const first = document.getElementById('grid');
host = document.createElement('div');
host.style.cssText = 'height:150px;margin-top:10px';
if (first !== null)
first.after(host);
else
document.body.append(host);
second = MaxGrid.createGrid(host, {
columns: [
{ id: 'name', title: '항목', width: 120, pinned: 'start' },
...Object.keys(MONTHS).map((id) => ({
id,
title: '실적률',
kind: 'number',
width: 70,
align: 'end',
})),
],
rows: ['목표 대비', '전년 대비'].map((name, r) => ({
id: r + 1,
name,
...Object.fromEntries(Object.keys(MONTHS).map((id, i) => [id, 80 + ((r * 11 + i * 7) % 40)])),
})),
rowKey: 'id',
ariaLabel: '실적률 그리드',
});
const off = api.on('gridsUnaligned', () => log({ ko: '연결이 끊겼어요.', en: 'The link was removed.' }));
connect(api, 'x');
log({
ko: '위 그리드를 가로로 스크롤하면 아래 그리드가 같은 위치로 따라가요.',
en: 'Scroll the top grid sideways and the bottom grid follows to the same position.',
});
return () => {
off();
link?.unlink();
second?.destroy();
host?.remove();
second = null;
host = null;
link = null;
};
}
const actions = {
// 맞출 방향을 바꿔요. none이면 두 그리드가 따로 움직여요.
scroll: (api, value) => connect(api, value === 'both' || value === 'none' || value === 'y' ? value : 'x'),
// 위 그리드를 끝까지 스크롤해요.
end: (api) => api.setScroll({ left: 100000 }),
start: (api) => api.setScroll({ left: 0 }),
};
const api = MaxGrid.createGrid(document.getElementById('grid'), options);
setup(api, (message) => {
const item = document.createElement('li');
item.textContent =
typeof message === 'string' ? message : navigator.language.startsWith('ko') ? message.ko : message.en;
document.getElementById('log').prepend(item);
});
document.getElementById('scroll').addEventListener('change', (event) => actions.scroll(api, event.target.value));
document.getElementById('end').addEventListener('click', () => actions.end(api));
document.getElementById('start').addEventListener('click', () => actions.start(api));
</script>
</body>
</html>버튼을 누르면 이 예제의 코드가 StackBlitz나 CodeSandbox로 전송돼요. 누르기 전에는 아무것도 보내지 않아요.
import { useEffect } from 'react';
import { Grid, useGridApi } from '@maxgrid/react';
import { actions, options, setup, type Row } from './example';
export function ExampleGrid() {
const [api, gridRef] = useGridApi<Row>();
useEffect(() => (api ? setup(api, console.log) : undefined), [api]);
return (
<>
<div className="toolbar">
<select
aria-label="맞출 방향"
disabled={!api}
onChange={(event) => api && actions.scroll(api, event.target.value)}
>
<option value="x">가로(x)</option>
<option value="y">세로(y)</option>
<option value="both">둘 다</option>
<option value="none">맞추지 않음(none)</option>
</select>
<button
type="button"
disabled={!api}
onClick={() => api && actions.end(api)}
>끝으로</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.start(api)}
>처음으로</button>
</div>
<Grid style={{ height: 170 }} ref={gridRef} options={options} />
</>
);
}import type { GridApi, GridOptions } from '@maxgrid/react';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
name: string;
[key: string]: string | number;
}
declare const MaxGrid: {
createGrid(container: HTMLElement, options: GridOptions<Row>): GridApi<Row>;
};
// 두 그리드는 컬럼이 서로 달라요. 컬럼 폭·순서는 맞추지 않고(columns: []) 스크롤만 따라가게 해요.
const MONTHS: Record<string, string> = {
m1: '1월',
m2: '2월',
m3: '3월',
m4: '4월',
m5: '5월',
m6: '6월',
m7: '7월',
m8: '8월',
m9: '9월',
m10: '10월',
m11: '11월',
m12: '12월',
};
export const options: GridOptions<Row> = {
columns: [
{ id: 'name', title: '지점', width: 140, pinned: 'start' },
...Object.entries(MONTHS).map(([id, title]) => ({
id,
title,
kind: 'number' as const,
width: 110,
align: 'end' as const,
})),
],
rows: ['서울 지점', '부산 지점', '대구 지점'].map((name, r) => ({
id: r + 1,
name,
...Object.fromEntries(Object.keys(MONTHS).map((id, i) => [id, 100 + ((r * 37 + i * 53) % 90)])),
})),
rowKey: 'id',
};
let second: GridApi<Row> | null = null;
let host: HTMLElement | null = null;
let link: { unlink(): void } | null = null;
let say: (message: LogText) => void = () => {};
function connect(api: GridApi<Row>, scroll: 'x' | 'y' | 'both' | 'none'): void {
link?.unlink();
link = second === null ? null : api.alignWith(second, { scroll, columns: [] });
say({ ko: `스크롤 맞춤: ${scroll}`, en: `Scroll alignment: ${scroll}` });
}
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
const first = document.getElementById('grid');
host = document.createElement('div');
host.style.cssText = 'height:150px;margin-top:10px';
if (first !== null) first.after(host);
else document.body.append(host);
second = MaxGrid.createGrid(host, {
columns: [
{ id: 'name', title: '항목', width: 120, pinned: 'start' },
...Object.keys(MONTHS).map((id) => ({
id,
title: '실적률',
kind: 'number' as const,
width: 70,
align: 'end' as const,
})),
],
rows: ['목표 대비', '전년 대비'].map((name, r) => ({
id: r + 1,
name,
...Object.fromEntries(Object.keys(MONTHS).map((id, i) => [id, 80 + ((r * 11 + i * 7) % 40)])),
})),
rowKey: 'id',
ariaLabel: '실적률 그리드',
});
const off = api.on('gridsUnaligned', () =>
log({ ko: '연결이 끊겼어요.', en: 'The link was removed.' }),
);
connect(api, 'x');
log({
ko: '위 그리드를 가로로 스크롤하면 아래 그리드가 같은 위치로 따라가요.',
en: 'Scroll the top grid sideways and the bottom grid follows to the same position.',
});
return () => {
off();
link?.unlink();
second?.destroy();
host?.remove();
second = null;
host = null;
link = null;
};
}
export const actions = {
// 맞출 방향을 바꿔요. none이면 두 그리드가 따로 움직여요.
scroll: (api: GridApi<Row>, value?: string) =>
connect(api, value === 'both' || value === 'none' || value === 'y' ? value : 'x'),
// 위 그리드를 끝까지 스크롤해요.
end: (api: GridApi<Row>) => api.setScroll({ left: 100000 }),
start: (api: GridApi<Row>) => api.setScroll({ left: 0 }),
};버튼을 누르면 이 예제의 코드가 StackBlitz나 CodeSandbox로 전송돼요. 누르기 전에는 아무것도 보내지 않아요.
<script setup lang="ts">
import { onBeforeUnmount, shallowRef } from 'vue';
import { Grid, type GridApi } from '@maxgrid/vue';
import { actions, options, setup, type Row } from './example';
const api = shallowRef<GridApi<Row> | null>(null);
let stop: (() => void) | undefined;
function onReady(event: { api: GridApi<Row> }) {
api.value = event.api;
stop = setup(event.api, console.log);
}
onBeforeUnmount(() => stop?.());
</script>
<template>
<div class="toolbar">
<select
aria-label="맞출 방향"
:disabled="!api"
@change="api && actions.scroll(api, ($event.target as HTMLSelectElement).value)"
>
<option value="x" selected>가로(x)</option>
<option value="y">세로(y)</option>
<option value="both">둘 다</option>
<option value="none">맞추지 않음(none)</option>
</select>
<button type="button" :disabled="!api" @click="api && actions.end(api)">끝으로</button>
<button type="button" :disabled="!api" @click="api && actions.start(api)">처음으로</button>
</div>
<Grid style="height: 170px" :options="options" @ready="onReady" />
</template>import type { GridApi, GridOptions } from '@maxgrid/vue';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
name: string;
[key: string]: string | number;
}
declare const MaxGrid: {
createGrid(container: HTMLElement, options: GridOptions<Row>): GridApi<Row>;
};
// 두 그리드는 컬럼이 서로 달라요. 컬럼 폭·순서는 맞추지 않고(columns: []) 스크롤만 따라가게 해요.
const MONTHS: Record<string, string> = {
m1: '1월',
m2: '2월',
m3: '3월',
m4: '4월',
m5: '5월',
m6: '6월',
m7: '7월',
m8: '8월',
m9: '9월',
m10: '10월',
m11: '11월',
m12: '12월',
};
export const options: GridOptions<Row> = {
columns: [
{ id: 'name', title: '지점', width: 140, pinned: 'start' },
...Object.entries(MONTHS).map(([id, title]) => ({
id,
title,
kind: 'number' as const,
width: 110,
align: 'end' as const,
})),
],
rows: ['서울 지점', '부산 지점', '대구 지점'].map((name, r) => ({
id: r + 1,
name,
...Object.fromEntries(Object.keys(MONTHS).map((id, i) => [id, 100 + ((r * 37 + i * 53) % 90)])),
})),
rowKey: 'id',
};
let second: GridApi<Row> | null = null;
let host: HTMLElement | null = null;
let link: { unlink(): void } | null = null;
let say: (message: LogText) => void = () => {};
function connect(api: GridApi<Row>, scroll: 'x' | 'y' | 'both' | 'none'): void {
link?.unlink();
link = second === null ? null : api.alignWith(second, { scroll, columns: [] });
say({ ko: `스크롤 맞춤: ${scroll}`, en: `Scroll alignment: ${scroll}` });
}
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
const first = document.getElementById('grid');
host = document.createElement('div');
host.style.cssText = 'height:150px;margin-top:10px';
if (first !== null) first.after(host);
else document.body.append(host);
second = MaxGrid.createGrid(host, {
columns: [
{ id: 'name', title: '항목', width: 120, pinned: 'start' },
...Object.keys(MONTHS).map((id) => ({
id,
title: '실적률',
kind: 'number' as const,
width: 70,
align: 'end' as const,
})),
],
rows: ['목표 대비', '전년 대비'].map((name, r) => ({
id: r + 1,
name,
...Object.fromEntries(Object.keys(MONTHS).map((id, i) => [id, 80 + ((r * 11 + i * 7) % 40)])),
})),
rowKey: 'id',
ariaLabel: '실적률 그리드',
});
const off = api.on('gridsUnaligned', () =>
log({ ko: '연결이 끊겼어요.', en: 'The link was removed.' }),
);
connect(api, 'x');
log({
ko: '위 그리드를 가로로 스크롤하면 아래 그리드가 같은 위치로 따라가요.',
en: 'Scroll the top grid sideways and the bottom grid follows to the same position.',
});
return () => {
off();
link?.unlink();
second?.destroy();
host?.remove();
second = null;
host = null;
link = null;
};
}
export const actions = {
// 맞출 방향을 바꿔요. none이면 두 그리드가 따로 움직여요.
scroll: (api: GridApi<Row>, value?: string) =>
connect(api, value === 'both' || value === 'none' || value === 'y' ? value : 'x'),
// 위 그리드를 끝까지 스크롤해요.
end: (api: GridApi<Row>) => api.setScroll({ left: 100000 }),
start: (api: GridApi<Row>) => api.setScroll({ left: 0 }),
};버튼을 누르면 이 예제의 코드가 StackBlitz나 CodeSandbox로 전송돼요. 누르기 전에는 아무것도 보내지 않아요.
import { Component, OnDestroy } from '@angular/core';
import { GridComponent, isGridEvent, type GridApi, type GridEventMessage } from '@maxgrid/angular';
import { actions, options, setup, type Row } from './example';
@Component({
selector: 'app-example-grid',
standalone: true,
imports: [GridComponent],
template: `
<div class="toolbar">
<select
aria-label="맞출 방향"
[disabled]="!api"
(change)="api && actions.scroll(api, $any($event.target).value)"
>
<option value="x" selected>가로(x)</option>
<option value="y">세로(y)</option>
<option value="both">둘 다</option>
<option value="none">맞추지 않음(none)</option>
</select>
<button
type="button"
[disabled]="!api"
(click)="api && actions.end(api)"
>끝으로</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.start(api)"
>처음으로</button>
</div>
<mx-grid style="height: 170px" [options]="options" [events]="relayed" (gridEvent)="onEvent($event)" />
`,
})
export class ExampleGridComponent implements OnDestroy {
readonly options = options;
readonly actions = actions;
readonly relayed = ['ready'] as const;
api: GridApi<Row> | null = null;
private stop: (() => void) | null = null;
onEvent(event: GridEventMessage<Row>): void {
if (isGridEvent(event, 'ready')) {
this.api = event.payload.api;
this.stop = setup(this.api, console.log);
}
}
ngOnDestroy(): void {
this.stop?.();
}
}import type { GridApi, GridOptions } from '@maxgrid/angular';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
name: string;
[key: string]: string | number;
}
declare const MaxGrid: {
createGrid(container: HTMLElement, options: GridOptions<Row>): GridApi<Row>;
};
// 두 그리드는 컬럼이 서로 달라요. 컬럼 폭·순서는 맞추지 않고(columns: []) 스크롤만 따라가게 해요.
const MONTHS: Record<string, string> = {
m1: '1월',
m2: '2월',
m3: '3월',
m4: '4월',
m5: '5월',
m6: '6월',
m7: '7월',
m8: '8월',
m9: '9월',
m10: '10월',
m11: '11월',
m12: '12월',
};
export const options: GridOptions<Row> = {
columns: [
{ id: 'name', title: '지점', width: 140, pinned: 'start' },
...Object.entries(MONTHS).map(([id, title]) => ({
id,
title,
kind: 'number' as const,
width: 110,
align: 'end' as const,
})),
],
rows: ['서울 지점', '부산 지점', '대구 지점'].map((name, r) => ({
id: r + 1,
name,
...Object.fromEntries(Object.keys(MONTHS).map((id, i) => [id, 100 + ((r * 37 + i * 53) % 90)])),
})),
rowKey: 'id',
};
let second: GridApi<Row> | null = null;
let host: HTMLElement | null = null;
let link: { unlink(): void } | null = null;
let say: (message: LogText) => void = () => {};
function connect(api: GridApi<Row>, scroll: 'x' | 'y' | 'both' | 'none'): void {
link?.unlink();
link = second === null ? null : api.alignWith(second, { scroll, columns: [] });
say({ ko: `스크롤 맞춤: ${scroll}`, en: `Scroll alignment: ${scroll}` });
}
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
const first = document.getElementById('grid');
host = document.createElement('div');
host.style.cssText = 'height:150px;margin-top:10px';
if (first !== null) first.after(host);
else document.body.append(host);
second = MaxGrid.createGrid(host, {
columns: [
{ id: 'name', title: '항목', width: 120, pinned: 'start' },
...Object.keys(MONTHS).map((id) => ({
id,
title: '실적률',
kind: 'number' as const,
width: 70,
align: 'end' as const,
})),
],
rows: ['목표 대비', '전년 대비'].map((name, r) => ({
id: r + 1,
name,
...Object.fromEntries(Object.keys(MONTHS).map((id, i) => [id, 80 + ((r * 11 + i * 7) % 40)])),
})),
rowKey: 'id',
ariaLabel: '실적률 그리드',
});
const off = api.on('gridsUnaligned', () =>
log({ ko: '연결이 끊겼어요.', en: 'The link was removed.' }),
);
connect(api, 'x');
log({
ko: '위 그리드를 가로로 스크롤하면 아래 그리드가 같은 위치로 따라가요.',
en: 'Scroll the top grid sideways and the bottom grid follows to the same position.',
});
return () => {
off();
link?.unlink();
second?.destroy();
host?.remove();
second = null;
host = null;
link = null;
};
}
export const actions = {
// 맞출 방향을 바꿔요. none이면 두 그리드가 따로 움직여요.
scroll: (api: GridApi<Row>, value?: string) =>
connect(api, value === 'both' || value === 'none' || value === 'y' ? value : 'x'),
// 위 그리드를 끝까지 스크롤해요.
end: (api: GridApi<Row>) => api.setScroll({ left: 100000 }),
start: (api: GridApi<Row>) => api.setScroll({ left: 0 }),
};When you click, the example code is sent to StackBlitz or CodeSandbox. Nothing is sent before you click.
<div id="app">
<div class="toolbar">
<select aria-label="Direction" id="scroll">
<option value="x" selected>Horizontal (x)</option>
<option value="y">Vertical (y)</option>
<option value="both">Both</option>
<option value="none">None</option>
</select>
<button type="button" id="end">To end</button>
<button type="button" id="start">To start</button>
</div>
<div id="grid" style="height: 170px"></div>
</div>
<script type="module" src="./main.js"></script>import { createGrid } from 'maxgrid';
import { actions, options, setup } from './example';
const api = createGrid(document.getElementById('grid'), options);
setup(api, console.log);
document.getElementById('scroll').addEventListener('change', (event) => actions.scroll(api, event.target.value));
document.getElementById('end').addEventListener('click', () => actions.end(api));
document.getElementById('start').addEventListener('click', () => actions.start(api));// The two grids have different columns. Column widths and order are not aligned (columns: []); only the scroll follows.
const MONTHS = {
m1: 'Jan',
m2: 'Feb',
m3: 'Mar',
m4: 'Apr',
m5: 'May',
m6: 'Jun',
m7: 'Jul',
m8: 'Aug',
m9: 'Sep',
m10: 'Oct',
m11: 'Nov',
m12: 'Dec',
};
export const options = {
columns: [
{ id: 'name', title: 'Branch', width: 140, pinned: 'start' },
...Object.entries(MONTHS).map(([id, title]) => ({
id,
title,
kind: 'number',
width: 110,
align: 'end',
})),
],
rows: ['Austin branch', 'Boston branch', 'Denver branch'].map((name, r) => ({
id: r + 1,
name,
...Object.fromEntries(Object.keys(MONTHS).map((id, i) => [id, 100 + ((r * 37 + i * 53) % 90)])),
})),
rowKey: 'id',
};
let second = null;
let host = null;
let link = null;
let say = () => { };
function connect(api, scroll) {
link?.unlink();
link = second === null ? null : api.alignWith(second, { scroll, columns: [] });
say(`Scroll alignment: ${scroll}`);
}
export function setup(api, log) {
say = log;
const first = document.getElementById('grid');
host = document.createElement('div');
host.style.cssText = 'height:150px;margin-top:10px';
if (first !== null)
first.after(host);
else
document.body.append(host);
second = MaxGrid.createGrid(host, {
columns: [
{ id: 'name', title: 'Item', width: 120, pinned: 'start' },
...Object.keys(MONTHS).map((id) => ({
id,
title: 'Rate',
kind: 'number',
width: 70,
align: 'end',
})),
],
rows: ['Vs target', 'Vs last year'].map((name, r) => ({
id: r + 1,
name,
...Object.fromEntries(Object.keys(MONTHS).map((id, i) => [id, 80 + ((r * 11 + i * 7) % 40)])),
})),
rowKey: 'id',
ariaLabel: 'Rate grid',
});
const off = api.on('gridsUnaligned', () => log('The link was removed.'));
connect(api, 'x');
log('Scroll the top grid sideways and the bottom grid follows to the same position.');
return () => {
off();
link?.unlink();
second?.destroy();
host?.remove();
second = null;
host = null;
link = null;
};
}
export const actions = {
// Change the direction to align. With none the two grids move on their own.
scroll: (api, value) => connect(api, value === 'both' || value === 'none' || value === 'y' ? value : 'x'),
// Scroll the top grid to the end.
end: (api) => api.setScroll({ left: 100000 }),
start: (api) => api.setScroll({ left: 0 }),
};<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Align only the scroll</title>
</head>
<body>
<div class="toolbar">
<select aria-label="Direction" id="scroll">
<option value="x" selected>Horizontal (x)</option>
<option value="y">Vertical (y)</option>
<option value="both">Both</option>
<option value="none">None</option>
</select>
<button type="button" id="end">To end</button>
<button type="button" id="start">To start</button>
</div>
<div id="grid" style="height: 170px"></div>
<ul id="log" aria-live="polite"></ul>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script>
// The two grids have different columns. Column widths and order are not aligned (columns: []); only the scroll follows.
const MONTHS = {
m1: 'Jan',
m2: 'Feb',
m3: 'Mar',
m4: 'Apr',
m5: 'May',
m6: 'Jun',
m7: 'Jul',
m8: 'Aug',
m9: 'Sep',
m10: 'Oct',
m11: 'Nov',
m12: 'Dec',
};
const options = {
columns: [
{ id: 'name', title: 'Branch', width: 140, pinned: 'start' },
...Object.entries(MONTHS).map(([id, title]) => ({
id,
title,
kind: 'number',
width: 110,
align: 'end',
})),
],
rows: ['Austin branch', 'Boston branch', 'Denver branch'].map((name, r) => ({
id: r + 1,
name,
...Object.fromEntries(Object.keys(MONTHS).map((id, i) => [id, 100 + ((r * 37 + i * 53) % 90)])),
})),
rowKey: 'id',
};
let second = null;
let host = null;
let link = null;
let say = () => { };
function connect(api, scroll) {
link?.unlink();
link = second === null ? null : api.alignWith(second, { scroll, columns: [] });
say(`Scroll alignment: ${scroll}`);
}
function setup(api, log) {
say = log;
const first = document.getElementById('grid');
host = document.createElement('div');
host.style.cssText = 'height:150px;margin-top:10px';
if (first !== null)
first.after(host);
else
document.body.append(host);
second = MaxGrid.createGrid(host, {
columns: [
{ id: 'name', title: 'Item', width: 120, pinned: 'start' },
...Object.keys(MONTHS).map((id) => ({
id,
title: 'Rate',
kind: 'number',
width: 70,
align: 'end',
})),
],
rows: ['Vs target', 'Vs last year'].map((name, r) => ({
id: r + 1,
name,
...Object.fromEntries(Object.keys(MONTHS).map((id, i) => [id, 80 + ((r * 11 + i * 7) % 40)])),
})),
rowKey: 'id',
ariaLabel: 'Rate grid',
});
const off = api.on('gridsUnaligned', () => log('The link was removed.'));
connect(api, 'x');
log('Scroll the top grid sideways and the bottom grid follows to the same position.');
return () => {
off();
link?.unlink();
second?.destroy();
host?.remove();
second = null;
host = null;
link = null;
};
}
const actions = {
// Change the direction to align. With none the two grids move on their own.
scroll: (api, value) => connect(api, value === 'both' || value === 'none' || value === 'y' ? value : 'x'),
// Scroll the top grid to the end.
end: (api) => api.setScroll({ left: 100000 }),
start: (api) => api.setScroll({ left: 0 }),
};
const api = MaxGrid.createGrid(document.getElementById('grid'), options);
setup(api, (message) => {
const item = document.createElement('li');
item.textContent =
typeof message === 'string' ? message : navigator.language.startsWith('ko') ? message.ko : message.en;
document.getElementById('log').prepend(item);
});
document.getElementById('scroll').addEventListener('change', (event) => actions.scroll(api, event.target.value));
document.getElementById('end').addEventListener('click', () => actions.end(api));
document.getElementById('start').addEventListener('click', () => actions.start(api));
</script>
</body>
</html>When you click, the example code is sent to StackBlitz or CodeSandbox. Nothing is sent before you click.
import { useEffect } from 'react';
import { Grid, useGridApi } from '@maxgrid/react';
import { actions, options, setup, type Row } from './example';
export function ExampleGrid() {
const [api, gridRef] = useGridApi<Row>();
useEffect(() => (api ? setup(api, console.log) : undefined), [api]);
return (
<>
<div className="toolbar">
<select
aria-label="Direction"
disabled={!api}
onChange={(event) => api && actions.scroll(api, event.target.value)}
>
<option value="x">Horizontal (x)</option>
<option value="y">Vertical (y)</option>
<option value="both">Both</option>
<option value="none">None</option>
</select>
<button
type="button"
disabled={!api}
onClick={() => api && actions.end(api)}
>To end</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.start(api)}
>To start</button>
</div>
<Grid style={{ height: 170 }} ref={gridRef} options={options} />
</>
);
}import type { GridApi, GridOptions } from '@maxgrid/react';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
name: string;
[key: string]: string | number;
}
declare const MaxGrid: {
createGrid(container: HTMLElement, options: GridOptions<Row>): GridApi<Row>;
};
// The two grids have different columns. Column widths and order are not aligned (columns: []); only the scroll follows.
const MONTHS: Record<string, string> = {
m1: 'Jan',
m2: 'Feb',
m3: 'Mar',
m4: 'Apr',
m5: 'May',
m6: 'Jun',
m7: 'Jul',
m8: 'Aug',
m9: 'Sep',
m10: 'Oct',
m11: 'Nov',
m12: 'Dec',
};
export const options: GridOptions<Row> = {
columns: [
{ id: 'name', title: 'Branch', width: 140, pinned: 'start' },
...Object.entries(MONTHS).map(([id, title]) => ({
id,
title,
kind: 'number' as const,
width: 110,
align: 'end' as const,
})),
],
rows: ['Austin branch', 'Boston branch', 'Denver branch'].map((name, r) => ({
id: r + 1,
name,
...Object.fromEntries(Object.keys(MONTHS).map((id, i) => [id, 100 + ((r * 37 + i * 53) % 90)])),
})),
rowKey: 'id',
};
let second: GridApi<Row> | null = null;
let host: HTMLElement | null = null;
let link: { unlink(): void } | null = null;
let say: (message: LogText) => void = () => {};
function connect(api: GridApi<Row>, scroll: 'x' | 'y' | 'both' | 'none'): void {
link?.unlink();
link = second === null ? null : api.alignWith(second, { scroll, columns: [] });
say(`Scroll alignment: ${scroll}`);
}
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
const first = document.getElementById('grid');
host = document.createElement('div');
host.style.cssText = 'height:150px;margin-top:10px';
if (first !== null) first.after(host);
else document.body.append(host);
second = MaxGrid.createGrid(host, {
columns: [
{ id: 'name', title: 'Item', width: 120, pinned: 'start' },
...Object.keys(MONTHS).map((id) => ({
id,
title: 'Rate',
kind: 'number' as const,
width: 70,
align: 'end' as const,
})),
],
rows: ['Vs target', 'Vs last year'].map((name, r) => ({
id: r + 1,
name,
...Object.fromEntries(Object.keys(MONTHS).map((id, i) => [id, 80 + ((r * 11 + i * 7) % 40)])),
})),
rowKey: 'id',
ariaLabel: 'Rate grid',
});
const off = api.on('gridsUnaligned', () => log('The link was removed.'));
connect(api, 'x');
log('Scroll the top grid sideways and the bottom grid follows to the same position.');
return () => {
off();
link?.unlink();
second?.destroy();
host?.remove();
second = null;
host = null;
link = null;
};
}
export const actions = {
// Change the direction to align. With none the two grids move on their own.
scroll: (api: GridApi<Row>, value?: string) =>
connect(api, value === 'both' || value === 'none' || value === 'y' ? value : 'x'),
// Scroll the top grid to the end.
end: (api: GridApi<Row>) => api.setScroll({ left: 100000 }),
start: (api: GridApi<Row>) => api.setScroll({ left: 0 }),
};When you click, the example code is sent to StackBlitz or CodeSandbox. Nothing is sent before you click.
<script setup lang="ts">
import { onBeforeUnmount, shallowRef } from 'vue';
import { Grid, type GridApi } from '@maxgrid/vue';
import { actions, options, setup, type Row } from './example';
const api = shallowRef<GridApi<Row> | null>(null);
let stop: (() => void) | undefined;
function onReady(event: { api: GridApi<Row> }) {
api.value = event.api;
stop = setup(event.api, console.log);
}
onBeforeUnmount(() => stop?.());
</script>
<template>
<div class="toolbar">
<select
aria-label="Direction"
:disabled="!api"
@change="api && actions.scroll(api, ($event.target as HTMLSelectElement).value)"
>
<option value="x" selected>Horizontal (x)</option>
<option value="y">Vertical (y)</option>
<option value="both">Both</option>
<option value="none">None</option>
</select>
<button type="button" :disabled="!api" @click="api && actions.end(api)">To end</button>
<button type="button" :disabled="!api" @click="api && actions.start(api)">To start</button>
</div>
<Grid style="height: 170px" :options="options" @ready="onReady" />
</template>import type { GridApi, GridOptions } from '@maxgrid/vue';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
name: string;
[key: string]: string | number;
}
declare const MaxGrid: {
createGrid(container: HTMLElement, options: GridOptions<Row>): GridApi<Row>;
};
// The two grids have different columns. Column widths and order are not aligned (columns: []); only the scroll follows.
const MONTHS: Record<string, string> = {
m1: 'Jan',
m2: 'Feb',
m3: 'Mar',
m4: 'Apr',
m5: 'May',
m6: 'Jun',
m7: 'Jul',
m8: 'Aug',
m9: 'Sep',
m10: 'Oct',
m11: 'Nov',
m12: 'Dec',
};
export const options: GridOptions<Row> = {
columns: [
{ id: 'name', title: 'Branch', width: 140, pinned: 'start' },
...Object.entries(MONTHS).map(([id, title]) => ({
id,
title,
kind: 'number' as const,
width: 110,
align: 'end' as const,
})),
],
rows: ['Austin branch', 'Boston branch', 'Denver branch'].map((name, r) => ({
id: r + 1,
name,
...Object.fromEntries(Object.keys(MONTHS).map((id, i) => [id, 100 + ((r * 37 + i * 53) % 90)])),
})),
rowKey: 'id',
};
let second: GridApi<Row> | null = null;
let host: HTMLElement | null = null;
let link: { unlink(): void } | null = null;
let say: (message: LogText) => void = () => {};
function connect(api: GridApi<Row>, scroll: 'x' | 'y' | 'both' | 'none'): void {
link?.unlink();
link = second === null ? null : api.alignWith(second, { scroll, columns: [] });
say(`Scroll alignment: ${scroll}`);
}
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
const first = document.getElementById('grid');
host = document.createElement('div');
host.style.cssText = 'height:150px;margin-top:10px';
if (first !== null) first.after(host);
else document.body.append(host);
second = MaxGrid.createGrid(host, {
columns: [
{ id: 'name', title: 'Item', width: 120, pinned: 'start' },
...Object.keys(MONTHS).map((id) => ({
id,
title: 'Rate',
kind: 'number' as const,
width: 70,
align: 'end' as const,
})),
],
rows: ['Vs target', 'Vs last year'].map((name, r) => ({
id: r + 1,
name,
...Object.fromEntries(Object.keys(MONTHS).map((id, i) => [id, 80 + ((r * 11 + i * 7) % 40)])),
})),
rowKey: 'id',
ariaLabel: 'Rate grid',
});
const off = api.on('gridsUnaligned', () => log('The link was removed.'));
connect(api, 'x');
log('Scroll the top grid sideways and the bottom grid follows to the same position.');
return () => {
off();
link?.unlink();
second?.destroy();
host?.remove();
second = null;
host = null;
link = null;
};
}
export const actions = {
// Change the direction to align. With none the two grids move on their own.
scroll: (api: GridApi<Row>, value?: string) =>
connect(api, value === 'both' || value === 'none' || value === 'y' ? value : 'x'),
// Scroll the top grid to the end.
end: (api: GridApi<Row>) => api.setScroll({ left: 100000 }),
start: (api: GridApi<Row>) => api.setScroll({ left: 0 }),
};When you click, the example code is sent to StackBlitz or CodeSandbox. Nothing is sent before you click.
import { Component, OnDestroy } from '@angular/core';
import { GridComponent, isGridEvent, type GridApi, type GridEventMessage } from '@maxgrid/angular';
import { actions, options, setup, type Row } from './example';
@Component({
selector: 'app-example-grid',
standalone: true,
imports: [GridComponent],
template: `
<div class="toolbar">
<select
aria-label="Direction"
[disabled]="!api"
(change)="api && actions.scroll(api, $any($event.target).value)"
>
<option value="x" selected>Horizontal (x)</option>
<option value="y">Vertical (y)</option>
<option value="both">Both</option>
<option value="none">None</option>
</select>
<button
type="button"
[disabled]="!api"
(click)="api && actions.end(api)"
>To end</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.start(api)"
>To start</button>
</div>
<mx-grid style="height: 170px" [options]="options" [events]="relayed" (gridEvent)="onEvent($event)" />
`,
})
export class ExampleGridComponent implements OnDestroy {
readonly options = options;
readonly actions = actions;
readonly relayed = ['ready'] as const;
api: GridApi<Row> | null = null;
private stop: (() => void) | null = null;
onEvent(event: GridEventMessage<Row>): void {
if (isGridEvent(event, 'ready')) {
this.api = event.payload.api;
this.stop = setup(this.api, console.log);
}
}
ngOnDestroy(): void {
this.stop?.();
}
}import type { GridApi, GridOptions } from '@maxgrid/angular';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
name: string;
[key: string]: string | number;
}
declare const MaxGrid: {
createGrid(container: HTMLElement, options: GridOptions<Row>): GridApi<Row>;
};
// The two grids have different columns. Column widths and order are not aligned (columns: []); only the scroll follows.
const MONTHS: Record<string, string> = {
m1: 'Jan',
m2: 'Feb',
m3: 'Mar',
m4: 'Apr',
m5: 'May',
m6: 'Jun',
m7: 'Jul',
m8: 'Aug',
m9: 'Sep',
m10: 'Oct',
m11: 'Nov',
m12: 'Dec',
};
export const options: GridOptions<Row> = {
columns: [
{ id: 'name', title: 'Branch', width: 140, pinned: 'start' },
...Object.entries(MONTHS).map(([id, title]) => ({
id,
title,
kind: 'number' as const,
width: 110,
align: 'end' as const,
})),
],
rows: ['Austin branch', 'Boston branch', 'Denver branch'].map((name, r) => ({
id: r + 1,
name,
...Object.fromEntries(Object.keys(MONTHS).map((id, i) => [id, 100 + ((r * 37 + i * 53) % 90)])),
})),
rowKey: 'id',
};
let second: GridApi<Row> | null = null;
let host: HTMLElement | null = null;
let link: { unlink(): void } | null = null;
let say: (message: LogText) => void = () => {};
function connect(api: GridApi<Row>, scroll: 'x' | 'y' | 'both' | 'none'): void {
link?.unlink();
link = second === null ? null : api.alignWith(second, { scroll, columns: [] });
say(`Scroll alignment: ${scroll}`);
}
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
const first = document.getElementById('grid');
host = document.createElement('div');
host.style.cssText = 'height:150px;margin-top:10px';
if (first !== null) first.after(host);
else document.body.append(host);
second = MaxGrid.createGrid(host, {
columns: [
{ id: 'name', title: 'Item', width: 120, pinned: 'start' },
...Object.keys(MONTHS).map((id) => ({
id,
title: 'Rate',
kind: 'number' as const,
width: 70,
align: 'end' as const,
})),
],
rows: ['Vs target', 'Vs last year'].map((name, r) => ({
id: r + 1,
name,
...Object.fromEntries(Object.keys(MONTHS).map((id, i) => [id, 80 + ((r * 11 + i * 7) % 40)])),
})),
rowKey: 'id',
ariaLabel: 'Rate grid',
});
const off = api.on('gridsUnaligned', () => log('The link was removed.'));
connect(api, 'x');
log('Scroll the top grid sideways and the bottom grid follows to the same position.');
return () => {
off();
link?.unlink();
second?.destroy();
host?.remove();
second = null;
host = null;
link = null;
};
}
export const actions = {
// Change the direction to align. With none the two grids move on their own.
scroll: (api: GridApi<Row>, value?: string) =>
connect(api, value === 'both' || value === 'none' || value === 'y' ? value : 'x'),
// Scroll the top grid to the end.
end: (api: GridApi<Row>) => api.setScroll({ left: 100000 }),
start: (api: GridApi<Row>) => api.setScroll({ left: 0 }),
};