끌어서 행 순서 바꾸기Reorder rows by dragging
rowDrag를 켜면 맨 앞에 끌기 손잡이 칸이 생겨요. 손잡이를 끌어 행을 옮기고, 선택한 행은 함께 움직여요. 되돌리기는 한 단계이고 정렬·필터 중에는 끌 수 없어요.With rowDrag on, a drag handle column appears at the front. Drag a handle to move a row; selected rows move together. Undo is one step, and rows cannot be dragged while sorting or filtering.
코드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">
<button type="button" id="select">2·3번 행 선택</button>
<button type="button" id="sortOn">정렬 켜기</button>
<button type="button" id="sortOff">정렬 끄기</button>
<button type="button" id="undo">되돌리기</button>
</div>
<div id="grid" style="height: 360px"></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('select').addEventListener('click', () => actions.select(api));
document.getElementById('sortOn').addEventListener('click', () => actions.sortOn(api));
document.getElementById('sortOff').addEventListener('click', () => actions.sortOff(api));
document.getElementById('undo').addEventListener('click', () => actions.undo(api));const owners = ['김서연', '박지훈', '이도윤', '최하은'];
const rows = [
'요구사항 정리',
'화면 설계',
'데이터 모델',
'API 구현',
'테스트 작성',
'문서 보완',
'배포 준비',
'회고',
].map((task, i) => ({ id: i + 1, task, owner: owners[i % 4] }));
// rowDrag: true는 맨 앞에 끌기 손잡이 칸을 두고, 손잡이를 끌어서 행 순서를 바꿔요(행 이동 API moveRows를 써요).
// 행을 골라 둔 채 선택된 행의 손잡이를 끌면 선택한 행이 모두 함께 움직여요.
export const options = {
columns: [
{ id: 'task', title: '할 일', width: 180 },
{ id: 'owner', title: '담당', width: 100 },
],
selection: 'multiple',
rowDrag: true,
rows,
rowKey: 'id',
};
export function setup(api, log) {
log({
ko: '맨 왼쪽 손잡이(⠿)를 끌어 행을 옮겨 보세요. 행 몇 개를 고른 뒤 그중 하나의 손잡이를 끌면 함께 움직여요.',
en: 'Drag the handle (⠿) on the left to move a row. Select a few rows and drag one of their handles to move them together.',
});
const offs = [
api.on('rowDragStarted', (e) => log({
ko: `끌기 시작: ${e.keys.length}개 행`,
en: `Drag started: ${e.keys.length} ${e.keys.length === 1 ? 'row' : 'rows'}`,
})),
api.on('rowDropped', (e) => log({
ko: `놓았어요: ${e.keys.join(', ')} → ${e.targetKey === null ? '맨 끝' : `${e.targetKey}번 ${e.position === 'before' ? '앞' : '뒤'}`}`,
en: `Dropped: ${e.keys.join(', ')} → ${e.targetKey === null ? 'the end' : `${e.position} row ${e.targetKey}`}`,
})),
api.on('rowDragCancelled', (e) => log({ ko: `취소했어요 (${e.reason})`, en: `Cancelled (${e.reason})` })),
];
return () => offs.forEach((off) => off());
}
export const actions = {
select: (api) => api.setSelectedKeys([2, 3]),
sortOn: (api) => api.setSortModel([{ columnId: 'task', direction: 'asc' }]),
sortOff: (api) => api.setSortModel([]),
undo: (api) => {
api.undo();
},
};<!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">
<button type="button" id="select">2·3번 행 선택</button>
<button type="button" id="sortOn">정렬 켜기</button>
<button type="button" id="sortOff">정렬 끄기</button>
<button type="button" id="undo">되돌리기</button>
</div>
<div id="grid" style="height: 360px"></div>
<ul id="log" aria-live="polite"></ul>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script>
const owners = ['김서연', '박지훈', '이도윤', '최하은'];
const rows = [
'요구사항 정리',
'화면 설계',
'데이터 모델',
'API 구현',
'테스트 작성',
'문서 보완',
'배포 준비',
'회고',
].map((task, i) => ({ id: i + 1, task, owner: owners[i % 4] }));
// rowDrag: true는 맨 앞에 끌기 손잡이 칸을 두고, 손잡이를 끌어서 행 순서를 바꿔요(행 이동 API moveRows를 써요).
// 행을 골라 둔 채 선택된 행의 손잡이를 끌면 선택한 행이 모두 함께 움직여요.
const options = {
columns: [
{ id: 'task', title: '할 일', width: 180 },
{ id: 'owner', title: '담당', width: 100 },
],
selection: 'multiple',
rowDrag: true,
rows,
rowKey: 'id',
};
function setup(api, log) {
log({
ko: '맨 왼쪽 손잡이(⠿)를 끌어 행을 옮겨 보세요. 행 몇 개를 고른 뒤 그중 하나의 손잡이를 끌면 함께 움직여요.',
en: 'Drag the handle (⠿) on the left to move a row. Select a few rows and drag one of their handles to move them together.',
});
const offs = [
api.on('rowDragStarted', (e) => log({
ko: `끌기 시작: ${e.keys.length}개 행`,
en: `Drag started: ${e.keys.length} ${e.keys.length === 1 ? 'row' : 'rows'}`,
})),
api.on('rowDropped', (e) => log({
ko: `놓았어요: ${e.keys.join(', ')} → ${e.targetKey === null ? '맨 끝' : `${e.targetKey}번 ${e.position === 'before' ? '앞' : '뒤'}`}`,
en: `Dropped: ${e.keys.join(', ')} → ${e.targetKey === null ? 'the end' : `${e.position} row ${e.targetKey}`}`,
})),
api.on('rowDragCancelled', (e) => log({ ko: `취소했어요 (${e.reason})`, en: `Cancelled (${e.reason})` })),
];
return () => offs.forEach((off) => off());
}
const actions = {
select: (api) => api.setSelectedKeys([2, 3]),
sortOn: (api) => api.setSortModel([{ columnId: 'task', direction: 'asc' }]),
sortOff: (api) => api.setSortModel([]),
undo: (api) => {
api.undo();
},
};
options.ariaLabel = "끌어서 행 순서 바꾸기";
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('select').addEventListener('click', () => actions.select(api));
document.getElementById('sortOn').addEventListener('click', () => actions.sortOn(api));
document.getElementById('sortOff').addEventListener('click', () => actions.sortOff(api));
document.getElementById('undo').addEventListener('click', () => actions.undo(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">
<button
type="button"
disabled={!api}
onClick={() => api && actions.select(api)}
>2·3번 행 선택</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.sortOn(api)}
>정렬 켜기</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.sortOff(api)}
>정렬 끄기</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.undo(api)}
>되돌리기</button>
</div>
<Grid style={{ height: 360 }} ref={gridRef} options={options} />
</>
);
}import type { GridApi, GridOptions } from '@maxgrid/react';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
task: string;
owner: string;
}
const owners = ['김서연', '박지훈', '이도윤', '최하은'];
const rows: Row[] = [
'요구사항 정리',
'화면 설계',
'데이터 모델',
'API 구현',
'테스트 작성',
'문서 보완',
'배포 준비',
'회고',
].map((task, i) => ({ id: i + 1, task, owner: owners[i % 4] as string }));
// rowDrag: true는 맨 앞에 끌기 손잡이 칸을 두고, 손잡이를 끌어서 행 순서를 바꿔요(행 이동 API moveRows를 써요).
// 행을 골라 둔 채 선택된 행의 손잡이를 끌면 선택한 행이 모두 함께 움직여요.
export const options: GridOptions<Row> = {
columns: [
{ id: 'task', title: '할 일', width: 180 },
{ id: 'owner', title: '담당', width: 100 },
],
selection: 'multiple',
rowDrag: true,
rows,
rowKey: 'id',
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
log({
ko: '맨 왼쪽 손잡이(⠿)를 끌어 행을 옮겨 보세요. 행 몇 개를 고른 뒤 그중 하나의 손잡이를 끌면 함께 움직여요.',
en: 'Drag the handle (⠿) on the left to move a row. Select a few rows and drag one of their handles to move them together.',
});
const offs = [
api.on('rowDragStarted', (e) =>
log({
ko: `끌기 시작: ${e.keys.length}개 행`,
en: `Drag started: ${e.keys.length} ${e.keys.length === 1 ? 'row' : 'rows'}`,
}),
),
api.on('rowDropped', (e) =>
log({
ko: `놓았어요: ${e.keys.join(', ')} → ${e.targetKey === null ? '맨 끝' : `${e.targetKey}번 ${e.position === 'before' ? '앞' : '뒤'}`}`,
en: `Dropped: ${e.keys.join(', ')} → ${e.targetKey === null ? 'the end' : `${e.position} row ${e.targetKey}`}`,
}),
),
api.on('rowDragCancelled', (e) =>
log({ ko: `취소했어요 (${e.reason})`, en: `Cancelled (${e.reason})` }),
),
];
return () => offs.forEach((off) => off());
}
export const actions = {
select: (api: GridApi<Row>) => api.setSelectedKeys([2, 3]),
sortOn: (api: GridApi<Row>) => api.setSortModel([{ columnId: 'task', direction: 'asc' }]),
sortOff: (api: GridApi<Row>) => api.setSortModel([]),
undo: (api: GridApi<Row>) => {
api.undo();
},
};버튼을 누르면 이 예제의 코드가 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">
<button type="button" :disabled="!api" @click="api && actions.select(api)">2·3번 행 선택</button>
<button type="button" :disabled="!api" @click="api && actions.sortOn(api)">정렬 켜기</button>
<button type="button" :disabled="!api" @click="api && actions.sortOff(api)">정렬 끄기</button>
<button type="button" :disabled="!api" @click="api && actions.undo(api)">되돌리기</button>
</div>
<Grid style="height: 360px" :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;
task: string;
owner: string;
}
const owners = ['김서연', '박지훈', '이도윤', '최하은'];
const rows: Row[] = [
'요구사항 정리',
'화면 설계',
'데이터 모델',
'API 구현',
'테스트 작성',
'문서 보완',
'배포 준비',
'회고',
].map((task, i) => ({ id: i + 1, task, owner: owners[i % 4] as string }));
// rowDrag: true는 맨 앞에 끌기 손잡이 칸을 두고, 손잡이를 끌어서 행 순서를 바꿔요(행 이동 API moveRows를 써요).
// 행을 골라 둔 채 선택된 행의 손잡이를 끌면 선택한 행이 모두 함께 움직여요.
export const options: GridOptions<Row> = {
columns: [
{ id: 'task', title: '할 일', width: 180 },
{ id: 'owner', title: '담당', width: 100 },
],
selection: 'multiple',
rowDrag: true,
rows,
rowKey: 'id',
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
log({
ko: '맨 왼쪽 손잡이(⠿)를 끌어 행을 옮겨 보세요. 행 몇 개를 고른 뒤 그중 하나의 손잡이를 끌면 함께 움직여요.',
en: 'Drag the handle (⠿) on the left to move a row. Select a few rows and drag one of their handles to move them together.',
});
const offs = [
api.on('rowDragStarted', (e) =>
log({
ko: `끌기 시작: ${e.keys.length}개 행`,
en: `Drag started: ${e.keys.length} ${e.keys.length === 1 ? 'row' : 'rows'}`,
}),
),
api.on('rowDropped', (e) =>
log({
ko: `놓았어요: ${e.keys.join(', ')} → ${e.targetKey === null ? '맨 끝' : `${e.targetKey}번 ${e.position === 'before' ? '앞' : '뒤'}`}`,
en: `Dropped: ${e.keys.join(', ')} → ${e.targetKey === null ? 'the end' : `${e.position} row ${e.targetKey}`}`,
}),
),
api.on('rowDragCancelled', (e) =>
log({ ko: `취소했어요 (${e.reason})`, en: `Cancelled (${e.reason})` }),
),
];
return () => offs.forEach((off) => off());
}
export const actions = {
select: (api: GridApi<Row>) => api.setSelectedKeys([2, 3]),
sortOn: (api: GridApi<Row>) => api.setSortModel([{ columnId: 'task', direction: 'asc' }]),
sortOff: (api: GridApi<Row>) => api.setSortModel([]),
undo: (api: GridApi<Row>) => {
api.undo();
},
};버튼을 누르면 이 예제의 코드가 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">
<button
type="button"
[disabled]="!api"
(click)="api && actions.select(api)"
>2·3번 행 선택</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.sortOn(api)"
>정렬 켜기</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.sortOff(api)"
>정렬 끄기</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.undo(api)"
>되돌리기</button>
</div>
<mx-grid style="height: 360px" [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;
task: string;
owner: string;
}
const owners = ['김서연', '박지훈', '이도윤', '최하은'];
const rows: Row[] = [
'요구사항 정리',
'화면 설계',
'데이터 모델',
'API 구현',
'테스트 작성',
'문서 보완',
'배포 준비',
'회고',
].map((task, i) => ({ id: i + 1, task, owner: owners[i % 4] as string }));
// rowDrag: true는 맨 앞에 끌기 손잡이 칸을 두고, 손잡이를 끌어서 행 순서를 바꿔요(행 이동 API moveRows를 써요).
// 행을 골라 둔 채 선택된 행의 손잡이를 끌면 선택한 행이 모두 함께 움직여요.
export const options: GridOptions<Row> = {
columns: [
{ id: 'task', title: '할 일', width: 180 },
{ id: 'owner', title: '담당', width: 100 },
],
selection: 'multiple',
rowDrag: true,
rows,
rowKey: 'id',
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
log({
ko: '맨 왼쪽 손잡이(⠿)를 끌어 행을 옮겨 보세요. 행 몇 개를 고른 뒤 그중 하나의 손잡이를 끌면 함께 움직여요.',
en: 'Drag the handle (⠿) on the left to move a row. Select a few rows and drag one of their handles to move them together.',
});
const offs = [
api.on('rowDragStarted', (e) =>
log({
ko: `끌기 시작: ${e.keys.length}개 행`,
en: `Drag started: ${e.keys.length} ${e.keys.length === 1 ? 'row' : 'rows'}`,
}),
),
api.on('rowDropped', (e) =>
log({
ko: `놓았어요: ${e.keys.join(', ')} → ${e.targetKey === null ? '맨 끝' : `${e.targetKey}번 ${e.position === 'before' ? '앞' : '뒤'}`}`,
en: `Dropped: ${e.keys.join(', ')} → ${e.targetKey === null ? 'the end' : `${e.position} row ${e.targetKey}`}`,
}),
),
api.on('rowDragCancelled', (e) =>
log({ ko: `취소했어요 (${e.reason})`, en: `Cancelled (${e.reason})` }),
),
];
return () => offs.forEach((off) => off());
}
export const actions = {
select: (api: GridApi<Row>) => api.setSelectedKeys([2, 3]),
sortOn: (api: GridApi<Row>) => api.setSortModel([{ columnId: 'task', direction: 'asc' }]),
sortOff: (api: GridApi<Row>) => api.setSortModel([]),
undo: (api: GridApi<Row>) => {
api.undo();
},
};When you click, the example code is sent to StackBlitz or CodeSandbox. Nothing is sent before you click.
<div id="app">
<div class="toolbar">
<button type="button" id="select">Select rows 2 and 3</button>
<button type="button" id="sortOn">Sort on</button>
<button type="button" id="sortOff">Sort off</button>
<button type="button" id="undo">Undo</button>
</div>
<div id="grid" style="height: 360px"></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('select').addEventListener('click', () => actions.select(api));
document.getElementById('sortOn').addEventListener('click', () => actions.sortOn(api));
document.getElementById('sortOff').addEventListener('click', () => actions.sortOff(api));
document.getElementById('undo').addEventListener('click', () => actions.undo(api));const owners = ['Liam Carter', 'Emma Stone', 'Noah Reed', 'Olivia Hayes'];
const rows = [
'Gather requirements',
'Design screens',
'Data model',
'Build API',
'Write tests',
'Update docs',
'Prepare release',
'Retrospective',
].map((task, i) => ({ id: i + 1, task, owner: owners[i % 4] }));
// rowDrag: true adds a drag handle column at the front; drag a handle to reorder rows (uses the moveRows API).
// With rows selected, dragging the handle of a selected row moves all selected rows together.
export const options = {
columns: [
{ id: 'task', title: 'Task', width: 180 },
{ id: 'owner', title: 'Owner', width: 120 },
],
selection: 'multiple',
rowDrag: true,
rows,
rowKey: 'id',
};
export function setup(api, log) {
log('Drag the handle (⠿) on the left to move a row. Select a few rows and drag one of their handles to move them together.');
const offs = [
api.on('rowDragStarted', (e) => log(`Drag started: ${e.keys.length} ${e.keys.length === 1 ? 'row' : 'rows'}`)),
api.on('rowDropped', (e) => log(`Dropped: ${e.keys.join(', ')} → ${e.targetKey === null ? 'the end' : `${e.position} row ${e.targetKey}`}`)),
api.on('rowDragCancelled', (e) => log(`Cancelled (${e.reason})`)),
];
return () => offs.forEach((off) => off());
}
export const actions = {
select: (api) => api.setSelectedKeys([2, 3]),
sortOn: (api) => api.setSortModel([{ columnId: 'task', direction: 'asc' }]),
sortOff: (api) => api.setSortModel([]),
undo: (api) => {
api.undo();
},
};<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Reorder rows by dragging</title>
</head>
<body>
<div class="toolbar">
<button type="button" id="select">Select rows 2 and 3</button>
<button type="button" id="sortOn">Sort on</button>
<button type="button" id="sortOff">Sort off</button>
<button type="button" id="undo">Undo</button>
</div>
<div id="grid" style="height: 360px"></div>
<ul id="log" aria-live="polite"></ul>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script>
const owners = ['Liam Carter', 'Emma Stone', 'Noah Reed', 'Olivia Hayes'];
const rows = [
'Gather requirements',
'Design screens',
'Data model',
'Build API',
'Write tests',
'Update docs',
'Prepare release',
'Retrospective',
].map((task, i) => ({ id: i + 1, task, owner: owners[i % 4] }));
// rowDrag: true adds a drag handle column at the front; drag a handle to reorder rows (uses the moveRows API).
// With rows selected, dragging the handle of a selected row moves all selected rows together.
const options = {
columns: [
{ id: 'task', title: 'Task', width: 180 },
{ id: 'owner', title: 'Owner', width: 120 },
],
selection: 'multiple',
rowDrag: true,
rows,
rowKey: 'id',
};
function setup(api, log) {
log('Drag the handle (⠿) on the left to move a row. Select a few rows and drag one of their handles to move them together.');
const offs = [
api.on('rowDragStarted', (e) => log(`Drag started: ${e.keys.length} ${e.keys.length === 1 ? 'row' : 'rows'}`)),
api.on('rowDropped', (e) => log(`Dropped: ${e.keys.join(', ')} → ${e.targetKey === null ? 'the end' : `${e.position} row ${e.targetKey}`}`)),
api.on('rowDragCancelled', (e) => log(`Cancelled (${e.reason})`)),
];
return () => offs.forEach((off) => off());
}
const actions = {
select: (api) => api.setSelectedKeys([2, 3]),
sortOn: (api) => api.setSortModel([{ columnId: 'task', direction: 'asc' }]),
sortOff: (api) => api.setSortModel([]),
undo: (api) => {
api.undo();
},
};
options.ariaLabel = "Reorder rows by dragging";
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('select').addEventListener('click', () => actions.select(api));
document.getElementById('sortOn').addEventListener('click', () => actions.sortOn(api));
document.getElementById('sortOff').addEventListener('click', () => actions.sortOff(api));
document.getElementById('undo').addEventListener('click', () => actions.undo(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">
<button
type="button"
disabled={!api}
onClick={() => api && actions.select(api)}
>Select rows 2 and 3</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.sortOn(api)}
>Sort on</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.sortOff(api)}
>Sort off</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.undo(api)}
>Undo</button>
</div>
<Grid style={{ height: 360 }} ref={gridRef} options={options} />
</>
);
}import type { GridApi, GridOptions } from '@maxgrid/react';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
task: string;
owner: string;
}
const owners = ['Liam Carter', 'Emma Stone', 'Noah Reed', 'Olivia Hayes'];
const rows: Row[] = [
'Gather requirements',
'Design screens',
'Data model',
'Build API',
'Write tests',
'Update docs',
'Prepare release',
'Retrospective',
].map((task, i) => ({ id: i + 1, task, owner: owners[i % 4] as string }));
// rowDrag: true adds a drag handle column at the front; drag a handle to reorder rows (uses the moveRows API).
// With rows selected, dragging the handle of a selected row moves all selected rows together.
export const options: GridOptions<Row> = {
columns: [
{ id: 'task', title: 'Task', width: 180 },
{ id: 'owner', title: 'Owner', width: 120 },
],
selection: 'multiple',
rowDrag: true,
rows,
rowKey: 'id',
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
log(
'Drag the handle (⠿) on the left to move a row. Select a few rows and drag one of their handles to move them together.',
);
const offs = [
api.on('rowDragStarted', (e) =>
log(`Drag started: ${e.keys.length} ${e.keys.length === 1 ? 'row' : 'rows'}`),
),
api.on('rowDropped', (e) =>
log(
`Dropped: ${e.keys.join(', ')} → ${e.targetKey === null ? 'the end' : `${e.position} row ${e.targetKey}`}`,
),
),
api.on('rowDragCancelled', (e) => log(`Cancelled (${e.reason})`)),
];
return () => offs.forEach((off) => off());
}
export const actions = {
select: (api: GridApi<Row>) => api.setSelectedKeys([2, 3]),
sortOn: (api: GridApi<Row>) => api.setSortModel([{ columnId: 'task', direction: 'asc' }]),
sortOff: (api: GridApi<Row>) => api.setSortModel([]),
undo: (api: GridApi<Row>) => {
api.undo();
},
};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">
<button type="button" :disabled="!api" @click="api && actions.select(api)">Select rows 2 and 3</button>
<button type="button" :disabled="!api" @click="api && actions.sortOn(api)">Sort on</button>
<button type="button" :disabled="!api" @click="api && actions.sortOff(api)">Sort off</button>
<button type="button" :disabled="!api" @click="api && actions.undo(api)">Undo</button>
</div>
<Grid style="height: 360px" :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;
task: string;
owner: string;
}
const owners = ['Liam Carter', 'Emma Stone', 'Noah Reed', 'Olivia Hayes'];
const rows: Row[] = [
'Gather requirements',
'Design screens',
'Data model',
'Build API',
'Write tests',
'Update docs',
'Prepare release',
'Retrospective',
].map((task, i) => ({ id: i + 1, task, owner: owners[i % 4] as string }));
// rowDrag: true adds a drag handle column at the front; drag a handle to reorder rows (uses the moveRows API).
// With rows selected, dragging the handle of a selected row moves all selected rows together.
export const options: GridOptions<Row> = {
columns: [
{ id: 'task', title: 'Task', width: 180 },
{ id: 'owner', title: 'Owner', width: 120 },
],
selection: 'multiple',
rowDrag: true,
rows,
rowKey: 'id',
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
log(
'Drag the handle (⠿) on the left to move a row. Select a few rows and drag one of their handles to move them together.',
);
const offs = [
api.on('rowDragStarted', (e) =>
log(`Drag started: ${e.keys.length} ${e.keys.length === 1 ? 'row' : 'rows'}`),
),
api.on('rowDropped', (e) =>
log(
`Dropped: ${e.keys.join(', ')} → ${e.targetKey === null ? 'the end' : `${e.position} row ${e.targetKey}`}`,
),
),
api.on('rowDragCancelled', (e) => log(`Cancelled (${e.reason})`)),
];
return () => offs.forEach((off) => off());
}
export const actions = {
select: (api: GridApi<Row>) => api.setSelectedKeys([2, 3]),
sortOn: (api: GridApi<Row>) => api.setSortModel([{ columnId: 'task', direction: 'asc' }]),
sortOff: (api: GridApi<Row>) => api.setSortModel([]),
undo: (api: GridApi<Row>) => {
api.undo();
},
};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">
<button
type="button"
[disabled]="!api"
(click)="api && actions.select(api)"
>Select rows 2 and 3</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.sortOn(api)"
>Sort on</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.sortOff(api)"
>Sort off</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.undo(api)"
>Undo</button>
</div>
<mx-grid style="height: 360px" [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;
task: string;
owner: string;
}
const owners = ['Liam Carter', 'Emma Stone', 'Noah Reed', 'Olivia Hayes'];
const rows: Row[] = [
'Gather requirements',
'Design screens',
'Data model',
'Build API',
'Write tests',
'Update docs',
'Prepare release',
'Retrospective',
].map((task, i) => ({ id: i + 1, task, owner: owners[i % 4] as string }));
// rowDrag: true adds a drag handle column at the front; drag a handle to reorder rows (uses the moveRows API).
// With rows selected, dragging the handle of a selected row moves all selected rows together.
export const options: GridOptions<Row> = {
columns: [
{ id: 'task', title: 'Task', width: 180 },
{ id: 'owner', title: 'Owner', width: 120 },
],
selection: 'multiple',
rowDrag: true,
rows,
rowKey: 'id',
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
log(
'Drag the handle (⠿) on the left to move a row. Select a few rows and drag one of their handles to move them together.',
);
const offs = [
api.on('rowDragStarted', (e) =>
log(`Drag started: ${e.keys.length} ${e.keys.length === 1 ? 'row' : 'rows'}`),
),
api.on('rowDropped', (e) =>
log(
`Dropped: ${e.keys.join(', ')} → ${e.targetKey === null ? 'the end' : `${e.position} row ${e.targetKey}`}`,
),
),
api.on('rowDragCancelled', (e) => log(`Cancelled (${e.reason})`)),
];
return () => offs.forEach((off) => off());
}
export const actions = {
select: (api: GridApi<Row>) => api.setSelectedKeys([2, 3]),
sortOn: (api: GridApi<Row>) => api.setSortModel([{ columnId: 'task', direction: 'asc' }]),
sortOff: (api: GridApi<Row>) => api.setSortModel([]),
undo: (api: GridApi<Row>) => {
api.undo();
},
};