컬럼을 다른 그룹으로 옮기기Move a column to another group
moveColumnToGroup은 컬럼을 헤더 그룹 사이로 옮기거나(null이면 그룹에서 빼요) getParentGroup으로 지금 속한 그룹을 물어봐요. 그룹의 마지막 컬럼이 빠지면 빈 그룹은 사라져요.moveColumnToGroup moves a column between header groups (null takes it out) and getParentGroup tells which group it is in. A group that loses its last column disappears.
코드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="toB">연봉을 사람 그룹으로</button>
<button type="button" id="out">연봉을 그룹에서 빼기</button>
<button type="button" id="where">소속 보기</button>
</div>
<div id="grid" style="height: 240px"></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('toB').addEventListener('click', () => actions.toB(api));
document.getElementById('out').addEventListener('click', () => actions.out(api));
document.getElementById('where').addEventListener('click', () => actions.where(api));const COLUMNS = [
{ id: 'id', title: '사번', width: 80, align: 'end' },
{ id: 'name', title: '이름', width: 110 },
{ id: 'team', title: '팀', width: 110 },
{ id: 'city', title: '근무지', width: 100 },
{ id: 'salary', title: '연봉(만원)', kind: 'number', width: 120, align: 'end' },
];
const ROWS = [
{ id: 1001, name: '김민준', team: '개발팀', city: '서울', salary: 6200 },
{ id: 1002, name: '이서연', team: '디자인팀', city: '부산', salary: 4800 },
{ id: 1003, name: '박지호', team: '영업팀', city: '대구', salary: 7100 },
{ id: 1004, name: '최유나', team: '인사팀', city: '서울', salary: 3900 },
];
let say = () => { };
export const options = {
columns: COLUMNS,
rows: ROWS,
rowKey: 'id',
headerGroups: [
{ id: 'person', title: '사람', children: ['name', 'team'] },
{ id: 'hr', title: '인사', children: ['city', 'salary'] },
],
};
export function setup(_api, log) {
say = log;
return () => { };
}
export const actions = {
toB: (api) => {
api.moveColumnToGroup('salary', 'person');
// 그룹만 바꾸면 연봉은 제자리에 남아 '사람' 그룹이 둘로 갈라져요. 팀 바로 뒤로 옮겨 한 덩어리로 만들어요.
api.moveColumn('salary', api.getColumnOrder().indexOf('team') + 1);
say({ ko: "연봉을 '사람' 그룹으로 옮겼어요", en: "Moved Salary to the 'person' group" });
},
out: (api) => {
api.moveColumnToGroup('salary', null);
say({ ko: '연봉을 그룹에서 뺐어요', en: 'Took Salary out of its group' });
},
where: (api) => {
const group = api.getParentGroup('salary');
say(group === null
? { ko: '연봉은 어느 그룹에도 없어요', en: 'Salary is in no group' }
: { ko: `연봉의 그룹: ${group.title}`, en: `Salary group: ${group.title}` });
},
};<!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="toB">연봉을 사람 그룹으로</button>
<button type="button" id="out">연봉을 그룹에서 빼기</button>
<button type="button" id="where">소속 보기</button>
</div>
<div id="grid" style="height: 240px"></div>
<ul id="log" aria-live="polite"></ul>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script>
const COLUMNS = [
{ id: 'id', title: '사번', width: 80, align: 'end' },
{ id: 'name', title: '이름', width: 110 },
{ id: 'team', title: '팀', width: 110 },
{ id: 'city', title: '근무지', width: 100 },
{ id: 'salary', title: '연봉(만원)', kind: 'number', width: 120, align: 'end' },
];
const ROWS = [
{ id: 1001, name: '김민준', team: '개발팀', city: '서울', salary: 6200 },
{ id: 1002, name: '이서연', team: '디자인팀', city: '부산', salary: 4800 },
{ id: 1003, name: '박지호', team: '영업팀', city: '대구', salary: 7100 },
{ id: 1004, name: '최유나', team: '인사팀', city: '서울', salary: 3900 },
];
let say = () => { };
const options = {
columns: COLUMNS,
rows: ROWS,
rowKey: 'id',
headerGroups: [
{ id: 'person', title: '사람', children: ['name', 'team'] },
{ id: 'hr', title: '인사', children: ['city', 'salary'] },
],
};
function setup(_api, log) {
say = log;
return () => { };
}
const actions = {
toB: (api) => {
api.moveColumnToGroup('salary', 'person');
// 그룹만 바꾸면 연봉은 제자리에 남아 '사람' 그룹이 둘로 갈라져요. 팀 바로 뒤로 옮겨 한 덩어리로 만들어요.
api.moveColumn('salary', api.getColumnOrder().indexOf('team') + 1);
say({ ko: "연봉을 '사람' 그룹으로 옮겼어요", en: "Moved Salary to the 'person' group" });
},
out: (api) => {
api.moveColumnToGroup('salary', null);
say({ ko: '연봉을 그룹에서 뺐어요', en: 'Took Salary out of its group' });
},
where: (api) => {
const group = api.getParentGroup('salary');
say(group === null
? { ko: '연봉은 어느 그룹에도 없어요', en: 'Salary is in no group' }
: { ko: `연봉의 그룹: ${group.title}`, en: `Salary group: ${group.title}` });
},
};
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('toB').addEventListener('click', () => actions.toB(api));
document.getElementById('out').addEventListener('click', () => actions.out(api));
document.getElementById('where').addEventListener('click', () => actions.where(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.toB(api)}
>연봉을 사람 그룹으로</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.out(api)}
>연봉을 그룹에서 빼기</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.where(api)}
>소속 보기</button>
</div>
<Grid style={{ height: 240 }} ref={gridRef} options={options} />
</>
);
}import type { ColumnDef, GridApi, GridOptions } from '@maxgrid/react';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
name: string;
team: string;
city: string;
salary: number;
}
const COLUMNS: ColumnDef<Row>[] = [
{ id: 'id', title: '사번', width: 80, align: 'end' },
{ id: 'name', title: '이름', width: 110 },
{ id: 'team', title: '팀', width: 110 },
{ id: 'city', title: '근무지', width: 100 },
{ id: 'salary', title: '연봉(만원)', kind: 'number', width: 120, align: 'end' },
];
const ROWS: Row[] = [
{ id: 1001, name: '김민준', team: '개발팀', city: '서울', salary: 6200 },
{ id: 1002, name: '이서연', team: '디자인팀', city: '부산', salary: 4800 },
{ id: 1003, name: '박지호', team: '영업팀', city: '대구', salary: 7100 },
{ id: 1004, name: '최유나', team: '인사팀', city: '서울', salary: 3900 },
];
let say: (message: LogText) => void = () => {};
export const options: GridOptions<Row> = {
columns: COLUMNS,
rows: ROWS,
rowKey: 'id',
headerGroups: [
{ id: 'person', title: '사람', children: ['name', 'team'] },
{ id: 'hr', title: '인사', children: ['city', 'salary'] },
],
};
export function setup(_api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
return () => {};
}
export const actions = {
toB: (api: GridApi<Row>) => {
api.moveColumnToGroup('salary', 'person');
// 그룹만 바꾸면 연봉은 제자리에 남아 '사람' 그룹이 둘로 갈라져요. 팀 바로 뒤로 옮겨 한 덩어리로 만들어요.
api.moveColumn('salary', api.getColumnOrder().indexOf('team') + 1);
say({ ko: "연봉을 '사람' 그룹으로 옮겼어요", en: "Moved Salary to the 'person' group" });
},
out: (api: GridApi<Row>) => {
api.moveColumnToGroup('salary', null);
say({ ko: '연봉을 그룹에서 뺐어요', en: 'Took Salary out of its group' });
},
where: (api: GridApi<Row>) => {
const group = api.getParentGroup('salary');
say(
group === null
? { ko: '연봉은 어느 그룹에도 없어요', en: 'Salary is in no group' }
: { ko: `연봉의 그룹: ${group.title}`, en: `Salary group: ${group.title}` },
);
},
};버튼을 누르면 이 예제의 코드가 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.toB(api)">연봉을 사람 그룹으로</button>
<button type="button" :disabled="!api" @click="api && actions.out(api)">연봉을 그룹에서 빼기</button>
<button type="button" :disabled="!api" @click="api && actions.where(api)">소속 보기</button>
</div>
<Grid style="height: 240px" :options="options" @ready="onReady" />
</template>import type { ColumnDef, GridApi, GridOptions } from '@maxgrid/vue';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
name: string;
team: string;
city: string;
salary: number;
}
const COLUMNS: ColumnDef<Row>[] = [
{ id: 'id', title: '사번', width: 80, align: 'end' },
{ id: 'name', title: '이름', width: 110 },
{ id: 'team', title: '팀', width: 110 },
{ id: 'city', title: '근무지', width: 100 },
{ id: 'salary', title: '연봉(만원)', kind: 'number', width: 120, align: 'end' },
];
const ROWS: Row[] = [
{ id: 1001, name: '김민준', team: '개발팀', city: '서울', salary: 6200 },
{ id: 1002, name: '이서연', team: '디자인팀', city: '부산', salary: 4800 },
{ id: 1003, name: '박지호', team: '영업팀', city: '대구', salary: 7100 },
{ id: 1004, name: '최유나', team: '인사팀', city: '서울', salary: 3900 },
];
let say: (message: LogText) => void = () => {};
export const options: GridOptions<Row> = {
columns: COLUMNS,
rows: ROWS,
rowKey: 'id',
headerGroups: [
{ id: 'person', title: '사람', children: ['name', 'team'] },
{ id: 'hr', title: '인사', children: ['city', 'salary'] },
],
};
export function setup(_api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
return () => {};
}
export const actions = {
toB: (api: GridApi<Row>) => {
api.moveColumnToGroup('salary', 'person');
// 그룹만 바꾸면 연봉은 제자리에 남아 '사람' 그룹이 둘로 갈라져요. 팀 바로 뒤로 옮겨 한 덩어리로 만들어요.
api.moveColumn('salary', api.getColumnOrder().indexOf('team') + 1);
say({ ko: "연봉을 '사람' 그룹으로 옮겼어요", en: "Moved Salary to the 'person' group" });
},
out: (api: GridApi<Row>) => {
api.moveColumnToGroup('salary', null);
say({ ko: '연봉을 그룹에서 뺐어요', en: 'Took Salary out of its group' });
},
where: (api: GridApi<Row>) => {
const group = api.getParentGroup('salary');
say(
group === null
? { ko: '연봉은 어느 그룹에도 없어요', en: 'Salary is in no group' }
: { ko: `연봉의 그룹: ${group.title}`, en: `Salary group: ${group.title}` },
);
},
};버튼을 누르면 이 예제의 코드가 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.toB(api)"
>연봉을 사람 그룹으로</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.out(api)"
>연봉을 그룹에서 빼기</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.where(api)"
>소속 보기</button>
</div>
<mx-grid style="height: 240px" [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 { ColumnDef, GridApi, GridOptions } from '@maxgrid/angular';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
name: string;
team: string;
city: string;
salary: number;
}
const COLUMNS: ColumnDef<Row>[] = [
{ id: 'id', title: '사번', width: 80, align: 'end' },
{ id: 'name', title: '이름', width: 110 },
{ id: 'team', title: '팀', width: 110 },
{ id: 'city', title: '근무지', width: 100 },
{ id: 'salary', title: '연봉(만원)', kind: 'number', width: 120, align: 'end' },
];
const ROWS: Row[] = [
{ id: 1001, name: '김민준', team: '개발팀', city: '서울', salary: 6200 },
{ id: 1002, name: '이서연', team: '디자인팀', city: '부산', salary: 4800 },
{ id: 1003, name: '박지호', team: '영업팀', city: '대구', salary: 7100 },
{ id: 1004, name: '최유나', team: '인사팀', city: '서울', salary: 3900 },
];
let say: (message: LogText) => void = () => {};
export const options: GridOptions<Row> = {
columns: COLUMNS,
rows: ROWS,
rowKey: 'id',
headerGroups: [
{ id: 'person', title: '사람', children: ['name', 'team'] },
{ id: 'hr', title: '인사', children: ['city', 'salary'] },
],
};
export function setup(_api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
return () => {};
}
export const actions = {
toB: (api: GridApi<Row>) => {
api.moveColumnToGroup('salary', 'person');
// 그룹만 바꾸면 연봉은 제자리에 남아 '사람' 그룹이 둘로 갈라져요. 팀 바로 뒤로 옮겨 한 덩어리로 만들어요.
api.moveColumn('salary', api.getColumnOrder().indexOf('team') + 1);
say({ ko: "연봉을 '사람' 그룹으로 옮겼어요", en: "Moved Salary to the 'person' group" });
},
out: (api: GridApi<Row>) => {
api.moveColumnToGroup('salary', null);
say({ ko: '연봉을 그룹에서 뺐어요', en: 'Took Salary out of its group' });
},
where: (api: GridApi<Row>) => {
const group = api.getParentGroup('salary');
say(
group === null
? { ko: '연봉은 어느 그룹에도 없어요', en: 'Salary is in no group' }
: { ko: `연봉의 그룹: ${group.title}`, en: `Salary group: ${group.title}` },
);
},
};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="toB">Salary to People group</button>
<button type="button" id="out">Salary out of groups</button>
<button type="button" id="where">Where is Salary</button>
</div>
<div id="grid" style="height: 240px"></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('toB').addEventListener('click', () => actions.toB(api));
document.getElementById('out').addEventListener('click', () => actions.out(api));
document.getElementById('where').addEventListener('click', () => actions.where(api));const COLUMNS = [
{ id: 'id', title: 'Emp ID', width: 90, align: 'end' },
{ id: 'name', title: 'Name', width: 110 },
{ id: 'team', title: 'Team', width: 110 },
{ id: 'city', title: 'Office', width: 100 },
{ id: 'salary', title: 'Salary ($)', kind: 'number', width: 120, align: 'end' },
];
const ROWS = [
{ id: 1001, name: 'Liam Carter', team: 'Dev', city: 'Seattle', salary: 62000 },
{ id: 1002, name: 'Emma Stone', team: 'Design', city: 'Boston', salary: 48000 },
{ id: 1003, name: 'Noah Hayes', team: 'Sales', city: 'Denver', salary: 71000 },
{ id: 1004, name: 'Olivia Reed', team: 'HR', city: 'Seattle', salary: 39000 },
];
let say = () => { };
export const options = {
columns: COLUMNS,
rows: ROWS,
rowKey: 'id',
headerGroups: [
{ id: 'person', title: 'People', children: ['name', 'team'] },
{ id: 'hr', title: 'HR', children: ['city', 'salary'] },
],
};
export function setup(_api, log) {
say = log;
return () => { };
}
export const actions = {
toB: (api) => {
api.moveColumnToGroup('salary', 'person');
// Changing only the group leaves Salary where it was and splits the 'People' group in two. Move it right after Team to make one block.
api.moveColumn('salary', api.getColumnOrder().indexOf('team') + 1);
say("Moved Salary to the 'person' group");
},
out: (api) => {
api.moveColumnToGroup('salary', null);
say('Took Salary out of its group');
},
where: (api) => {
const group = api.getParentGroup('salary');
say(group === null ? 'Salary is in no group' : `Salary group: ${group.title}`);
},
};<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Move a column to another group</title>
</head>
<body>
<div class="toolbar">
<button type="button" id="toB">Salary to People group</button>
<button type="button" id="out">Salary out of groups</button>
<button type="button" id="where">Where is Salary</button>
</div>
<div id="grid" style="height: 240px"></div>
<ul id="log" aria-live="polite"></ul>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script>
const COLUMNS = [
{ id: 'id', title: 'Emp ID', width: 90, align: 'end' },
{ id: 'name', title: 'Name', width: 110 },
{ id: 'team', title: 'Team', width: 110 },
{ id: 'city', title: 'Office', width: 100 },
{ id: 'salary', title: 'Salary ($)', kind: 'number', width: 120, align: 'end' },
];
const ROWS = [
{ id: 1001, name: 'Liam Carter', team: 'Dev', city: 'Seattle', salary: 62000 },
{ id: 1002, name: 'Emma Stone', team: 'Design', city: 'Boston', salary: 48000 },
{ id: 1003, name: 'Noah Hayes', team: 'Sales', city: 'Denver', salary: 71000 },
{ id: 1004, name: 'Olivia Reed', team: 'HR', city: 'Seattle', salary: 39000 },
];
let say = () => { };
const options = {
columns: COLUMNS,
rows: ROWS,
rowKey: 'id',
headerGroups: [
{ id: 'person', title: 'People', children: ['name', 'team'] },
{ id: 'hr', title: 'HR', children: ['city', 'salary'] },
],
};
function setup(_api, log) {
say = log;
return () => { };
}
const actions = {
toB: (api) => {
api.moveColumnToGroup('salary', 'person');
// Changing only the group leaves Salary where it was and splits the 'People' group in two. Move it right after Team to make one block.
api.moveColumn('salary', api.getColumnOrder().indexOf('team') + 1);
say("Moved Salary to the 'person' group");
},
out: (api) => {
api.moveColumnToGroup('salary', null);
say('Took Salary out of its group');
},
where: (api) => {
const group = api.getParentGroup('salary');
say(group === null ? 'Salary is in no group' : `Salary group: ${group.title}`);
},
};
options.ariaLabel = "Move a column to another group";
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('toB').addEventListener('click', () => actions.toB(api));
document.getElementById('out').addEventListener('click', () => actions.out(api));
document.getElementById('where').addEventListener('click', () => actions.where(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.toB(api)}
>Salary to People group</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.out(api)}
>Salary out of groups</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.where(api)}
>Where is Salary</button>
</div>
<Grid style={{ height: 240 }} ref={gridRef} options={options} />
</>
);
}import type { ColumnDef, GridApi, GridOptions } from '@maxgrid/react';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
name: string;
team: string;
city: string;
salary: number;
}
const COLUMNS: ColumnDef<Row>[] = [
{ id: 'id', title: 'Emp ID', width: 90, align: 'end' },
{ id: 'name', title: 'Name', width: 110 },
{ id: 'team', title: 'Team', width: 110 },
{ id: 'city', title: 'Office', width: 100 },
{ id: 'salary', title: 'Salary ($)', kind: 'number', width: 120, align: 'end' },
];
const ROWS: Row[] = [
{ id: 1001, name: 'Liam Carter', team: 'Dev', city: 'Seattle', salary: 62000 },
{ id: 1002, name: 'Emma Stone', team: 'Design', city: 'Boston', salary: 48000 },
{ id: 1003, name: 'Noah Hayes', team: 'Sales', city: 'Denver', salary: 71000 },
{ id: 1004, name: 'Olivia Reed', team: 'HR', city: 'Seattle', salary: 39000 },
];
let say: (message: LogText) => void = () => {};
export const options: GridOptions<Row> = {
columns: COLUMNS,
rows: ROWS,
rowKey: 'id',
headerGroups: [
{ id: 'person', title: 'People', children: ['name', 'team'] },
{ id: 'hr', title: 'HR', children: ['city', 'salary'] },
],
};
export function setup(_api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
return () => {};
}
export const actions = {
toB: (api: GridApi<Row>) => {
api.moveColumnToGroup('salary', 'person');
// Changing only the group leaves Salary where it was and splits the 'People' group in two. Move it right after Team to make one block.
api.moveColumn('salary', api.getColumnOrder().indexOf('team') + 1);
say("Moved Salary to the 'person' group");
},
out: (api: GridApi<Row>) => {
api.moveColumnToGroup('salary', null);
say('Took Salary out of its group');
},
where: (api: GridApi<Row>) => {
const group = api.getParentGroup('salary');
say(group === null ? 'Salary is in no group' : `Salary group: ${group.title}`);
},
};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.toB(api)">Salary to People group</button>
<button type="button" :disabled="!api" @click="api && actions.out(api)">Salary out of groups</button>
<button type="button" :disabled="!api" @click="api && actions.where(api)">Where is Salary</button>
</div>
<Grid style="height: 240px" :options="options" @ready="onReady" />
</template>import type { ColumnDef, GridApi, GridOptions } from '@maxgrid/vue';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
name: string;
team: string;
city: string;
salary: number;
}
const COLUMNS: ColumnDef<Row>[] = [
{ id: 'id', title: 'Emp ID', width: 90, align: 'end' },
{ id: 'name', title: 'Name', width: 110 },
{ id: 'team', title: 'Team', width: 110 },
{ id: 'city', title: 'Office', width: 100 },
{ id: 'salary', title: 'Salary ($)', kind: 'number', width: 120, align: 'end' },
];
const ROWS: Row[] = [
{ id: 1001, name: 'Liam Carter', team: 'Dev', city: 'Seattle', salary: 62000 },
{ id: 1002, name: 'Emma Stone', team: 'Design', city: 'Boston', salary: 48000 },
{ id: 1003, name: 'Noah Hayes', team: 'Sales', city: 'Denver', salary: 71000 },
{ id: 1004, name: 'Olivia Reed', team: 'HR', city: 'Seattle', salary: 39000 },
];
let say: (message: LogText) => void = () => {};
export const options: GridOptions<Row> = {
columns: COLUMNS,
rows: ROWS,
rowKey: 'id',
headerGroups: [
{ id: 'person', title: 'People', children: ['name', 'team'] },
{ id: 'hr', title: 'HR', children: ['city', 'salary'] },
],
};
export function setup(_api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
return () => {};
}
export const actions = {
toB: (api: GridApi<Row>) => {
api.moveColumnToGroup('salary', 'person');
// Changing only the group leaves Salary where it was and splits the 'People' group in two. Move it right after Team to make one block.
api.moveColumn('salary', api.getColumnOrder().indexOf('team') + 1);
say("Moved Salary to the 'person' group");
},
out: (api: GridApi<Row>) => {
api.moveColumnToGroup('salary', null);
say('Took Salary out of its group');
},
where: (api: GridApi<Row>) => {
const group = api.getParentGroup('salary');
say(group === null ? 'Salary is in no group' : `Salary group: ${group.title}`);
},
};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.toB(api)"
>Salary to People group</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.out(api)"
>Salary out of groups</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.where(api)"
>Where is Salary</button>
</div>
<mx-grid style="height: 240px" [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 { ColumnDef, GridApi, GridOptions } from '@maxgrid/angular';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
name: string;
team: string;
city: string;
salary: number;
}
const COLUMNS: ColumnDef<Row>[] = [
{ id: 'id', title: 'Emp ID', width: 90, align: 'end' },
{ id: 'name', title: 'Name', width: 110 },
{ id: 'team', title: 'Team', width: 110 },
{ id: 'city', title: 'Office', width: 100 },
{ id: 'salary', title: 'Salary ($)', kind: 'number', width: 120, align: 'end' },
];
const ROWS: Row[] = [
{ id: 1001, name: 'Liam Carter', team: 'Dev', city: 'Seattle', salary: 62000 },
{ id: 1002, name: 'Emma Stone', team: 'Design', city: 'Boston', salary: 48000 },
{ id: 1003, name: 'Noah Hayes', team: 'Sales', city: 'Denver', salary: 71000 },
{ id: 1004, name: 'Olivia Reed', team: 'HR', city: 'Seattle', salary: 39000 },
];
let say: (message: LogText) => void = () => {};
export const options: GridOptions<Row> = {
columns: COLUMNS,
rows: ROWS,
rowKey: 'id',
headerGroups: [
{ id: 'person', title: 'People', children: ['name', 'team'] },
{ id: 'hr', title: 'HR', children: ['city', 'salary'] },
],
};
export function setup(_api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
return () => {};
}
export const actions = {
toB: (api: GridApi<Row>) => {
api.moveColumnToGroup('salary', 'person');
// Changing only the group leaves Salary where it was and splits the 'People' group in two. Move it right after Team to make one block.
api.moveColumn('salary', api.getColumnOrder().indexOf('team') + 1);
say("Moved Salary to the 'person' group");
},
out: (api: GridApi<Row>) => {
api.moveColumnToGroup('salary', null);
say('Took Salary out of its group');
},
where: (api: GridApi<Row>) => {
const group = api.getParentGroup('salary');
say(group === null ? 'Salary is in no group' : `Salary group: ${group.title}`);
},
};