컬럼 하나만 끼워 넣기Insert a single column
addColumn은 컬럼 정의 전체를 바꾸지 않고 하나만 더해요. 위치(index)와 헤더 그룹(groupId)을 고르고, fill을 켜면 defaultValue를 기존 행에 채워요. 지금까지 더하고 뺀 컬럼은 getAddedColumns/getRemovedColumns로 알 수 있어요.addColumn adds one column without replacing the whole list. Pick the position (index) and header group (groupId); fill writes defaultValue into existing rows. getAddedColumns and getRemovedColumns tell what changed so far.
코드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="first">앞에 끼우기</button>
<button type="button" id="group">그룹에 넣기</button>
<button type="button" id="fill">보너스 채우기</button>
<button type="button" id="remove">마지막 빼기</button>
<button type="button" id="changes">변경 내역</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('first').addEventListener('click', () => actions.first(api));
document.getElementById('group').addEventListener('click', () => actions.group(api));
document.getElementById('fill').addEventListener('click', () => actions.fill(api));
document.getElementById('remove').addEventListener('click', () => actions.remove(api));
document.getElementById('changes').addEventListener('click', () => actions.changes(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: 'work', title: '근무', children: ['team', 'city'] }],
};
export function setup(_api, log) {
say = log;
return () => { };
}
// 조사는 마지막 글자 소리에 맞춘다(숫자는 읽는 소리: 1 일, 3 삼, 6 육, 7 칠, 8 팔은 받침이 있다).
const eulReul = (word) => (/[13678]$/.test(word) ? '을' : '를');
let seq = 0;
export const actions = {
first: (api) => {
const id = `memo${++seq}`;
api.addColumn({ id, title: `메모 ${seq}`, width: 90 }, { index: 0 });
say({ ko: `'${id}'${eulReul(id)} 맨 앞에 끼웠어요`, en: `Inserted '${id}' first` });
},
group: (api) => {
const id = `grp${++seq}`;
api.addColumn({ id, title: `근무 ${seq}`, width: 90 }, { groupId: 'work' });
say({
ko: `'${id}'${eulReul(id)} '근무' 그룹에 넣었어요`,
en: `Added '${id}' to the Work group`,
});
},
fill: (api) => {
const id = `bonus${++seq}`;
api.addColumn({
id,
title: '보너스',
kind: 'number',
width: 100,
defaultValue: (row) => row.salary / 10,
}, { fill: true });
say({
ko: `'${id}'${eulReul(id)} 더하고 기존 행에 보너스를 채웠어요`,
en: `Added '${id}' and filled existing rows`,
});
},
remove: (api) => {
const last = api.getColumns().at(-1);
if (last === undefined || api.getColumns().length <= 2)
return say({ ko: '더 빼지 않아요', en: 'Keeping at least 2 columns' });
api.removeColumn(last.id);
say({ ko: `'${last.id}'${eulReul(last.id)} 뺐어요`, en: `Removed '${last.id}'` });
},
changes: (api) => {
say({
ko: `더한 컬럼: ${api.getAddedColumns().join(', ') || '없음'} / 뺀 컬럼: ${api.getRemovedColumns().join(', ') || '없음'}`,
en: `Added: ${api.getAddedColumns().join(', ') || 'none'} / Removed: ${api.getRemovedColumns().join(', ') || 'none'}`,
});
},
};<!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="first">앞에 끼우기</button>
<button type="button" id="group">그룹에 넣기</button>
<button type="button" id="fill">보너스 채우기</button>
<button type="button" id="remove">마지막 빼기</button>
<button type="button" id="changes">변경 내역</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: 'work', title: '근무', children: ['team', 'city'] }],
};
function setup(_api, log) {
say = log;
return () => { };
}
// 조사는 마지막 글자 소리에 맞춘다(숫자는 읽는 소리: 1 일, 3 삼, 6 육, 7 칠, 8 팔은 받침이 있다).
const eulReul = (word) => (/[13678]$/.test(word) ? '을' : '를');
let seq = 0;
const actions = {
first: (api) => {
const id = `memo${++seq}`;
api.addColumn({ id, title: `메모 ${seq}`, width: 90 }, { index: 0 });
say({ ko: `'${id}'${eulReul(id)} 맨 앞에 끼웠어요`, en: `Inserted '${id}' first` });
},
group: (api) => {
const id = `grp${++seq}`;
api.addColumn({ id, title: `근무 ${seq}`, width: 90 }, { groupId: 'work' });
say({
ko: `'${id}'${eulReul(id)} '근무' 그룹에 넣었어요`,
en: `Added '${id}' to the Work group`,
});
},
fill: (api) => {
const id = `bonus${++seq}`;
api.addColumn({
id,
title: '보너스',
kind: 'number',
width: 100,
defaultValue: (row) => row.salary / 10,
}, { fill: true });
say({
ko: `'${id}'${eulReul(id)} 더하고 기존 행에 보너스를 채웠어요`,
en: `Added '${id}' and filled existing rows`,
});
},
remove: (api) => {
const last = api.getColumns().at(-1);
if (last === undefined || api.getColumns().length <= 2)
return say({ ko: '더 빼지 않아요', en: 'Keeping at least 2 columns' });
api.removeColumn(last.id);
say({ ko: `'${last.id}'${eulReul(last.id)} 뺐어요`, en: `Removed '${last.id}'` });
},
changes: (api) => {
say({
ko: `더한 컬럼: ${api.getAddedColumns().join(', ') || '없음'} / 뺀 컬럼: ${api.getRemovedColumns().join(', ') || '없음'}`,
en: `Added: ${api.getAddedColumns().join(', ') || 'none'} / Removed: ${api.getRemovedColumns().join(', ') || 'none'}`,
});
},
};
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('first').addEventListener('click', () => actions.first(api));
document.getElementById('group').addEventListener('click', () => actions.group(api));
document.getElementById('fill').addEventListener('click', () => actions.fill(api));
document.getElementById('remove').addEventListener('click', () => actions.remove(api));
document.getElementById('changes').addEventListener('click', () => actions.changes(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.first(api)}
>앞에 끼우기</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.group(api)}
>그룹에 넣기</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.fill(api)}
>보너스 채우기</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.remove(api)}
>마지막 빼기</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.changes(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: 'work', title: '근무', children: ['team', 'city'] }],
};
export function setup(_api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
return () => {};
}
// 조사는 마지막 글자 소리에 맞춘다(숫자는 읽는 소리: 1 일, 3 삼, 6 육, 7 칠, 8 팔은 받침이 있다).
const eulReul = (word: string): string => (/[13678]$/.test(word) ? '을' : '를');
let seq = 0;
export const actions = {
first: (api: GridApi<Row>) => {
const id = `memo${++seq}`;
api.addColumn({ id, title: `메모 ${seq}`, width: 90 }, { index: 0 });
say({ ko: `'${id}'${eulReul(id)} 맨 앞에 끼웠어요`, en: `Inserted '${id}' first` });
},
group: (api: GridApi<Row>) => {
const id = `grp${++seq}`;
api.addColumn({ id, title: `근무 ${seq}`, width: 90 }, { groupId: 'work' });
say({
ko: `'${id}'${eulReul(id)} '근무' 그룹에 넣었어요`,
en: `Added '${id}' to the Work group`,
});
},
fill: (api: GridApi<Row>) => {
const id = `bonus${++seq}`;
api.addColumn(
{
id,
title: '보너스',
kind: 'number',
width: 100,
defaultValue: (row: Row) => row.salary / 10,
},
{ fill: true },
);
say({
ko: `'${id}'${eulReul(id)} 더하고 기존 행에 보너스를 채웠어요`,
en: `Added '${id}' and filled existing rows`,
});
},
remove: (api: GridApi<Row>) => {
const last = api.getColumns().at(-1);
if (last === undefined || api.getColumns().length <= 2)
return say({ ko: '더 빼지 않아요', en: 'Keeping at least 2 columns' });
api.removeColumn(last.id);
say({ ko: `'${last.id}'${eulReul(last.id)} 뺐어요`, en: `Removed '${last.id}'` });
},
changes: (api: GridApi<Row>) => {
say({
ko: `더한 컬럼: ${api.getAddedColumns().join(', ') || '없음'} / 뺀 컬럼: ${api.getRemovedColumns().join(', ') || '없음'}`,
en: `Added: ${api.getAddedColumns().join(', ') || 'none'} / Removed: ${api.getRemovedColumns().join(', ') || 'none'}`,
});
},
};버튼을 누르면 이 예제의 코드가 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.first(api)">앞에 끼우기</button>
<button type="button" :disabled="!api" @click="api && actions.group(api)">그룹에 넣기</button>
<button type="button" :disabled="!api" @click="api && actions.fill(api)">보너스 채우기</button>
<button type="button" :disabled="!api" @click="api && actions.remove(api)">마지막 빼기</button>
<button type="button" :disabled="!api" @click="api && actions.changes(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: 'work', title: '근무', children: ['team', 'city'] }],
};
export function setup(_api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
return () => {};
}
// 조사는 마지막 글자 소리에 맞춘다(숫자는 읽는 소리: 1 일, 3 삼, 6 육, 7 칠, 8 팔은 받침이 있다).
const eulReul = (word: string): string => (/[13678]$/.test(word) ? '을' : '를');
let seq = 0;
export const actions = {
first: (api: GridApi<Row>) => {
const id = `memo${++seq}`;
api.addColumn({ id, title: `메모 ${seq}`, width: 90 }, { index: 0 });
say({ ko: `'${id}'${eulReul(id)} 맨 앞에 끼웠어요`, en: `Inserted '${id}' first` });
},
group: (api: GridApi<Row>) => {
const id = `grp${++seq}`;
api.addColumn({ id, title: `근무 ${seq}`, width: 90 }, { groupId: 'work' });
say({
ko: `'${id}'${eulReul(id)} '근무' 그룹에 넣었어요`,
en: `Added '${id}' to the Work group`,
});
},
fill: (api: GridApi<Row>) => {
const id = `bonus${++seq}`;
api.addColumn(
{
id,
title: '보너스',
kind: 'number',
width: 100,
defaultValue: (row: Row) => row.salary / 10,
},
{ fill: true },
);
say({
ko: `'${id}'${eulReul(id)} 더하고 기존 행에 보너스를 채웠어요`,
en: `Added '${id}' and filled existing rows`,
});
},
remove: (api: GridApi<Row>) => {
const last = api.getColumns().at(-1);
if (last === undefined || api.getColumns().length <= 2)
return say({ ko: '더 빼지 않아요', en: 'Keeping at least 2 columns' });
api.removeColumn(last.id);
say({ ko: `'${last.id}'${eulReul(last.id)} 뺐어요`, en: `Removed '${last.id}'` });
},
changes: (api: GridApi<Row>) => {
say({
ko: `더한 컬럼: ${api.getAddedColumns().join(', ') || '없음'} / 뺀 컬럼: ${api.getRemovedColumns().join(', ') || '없음'}`,
en: `Added: ${api.getAddedColumns().join(', ') || 'none'} / Removed: ${api.getRemovedColumns().join(', ') || 'none'}`,
});
},
};버튼을 누르면 이 예제의 코드가 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.first(api)"
>앞에 끼우기</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.group(api)"
>그룹에 넣기</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.fill(api)"
>보너스 채우기</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.remove(api)"
>마지막 빼기</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.changes(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: 'work', title: '근무', children: ['team', 'city'] }],
};
export function setup(_api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
return () => {};
}
// 조사는 마지막 글자 소리에 맞춘다(숫자는 읽는 소리: 1 일, 3 삼, 6 육, 7 칠, 8 팔은 받침이 있다).
const eulReul = (word: string): string => (/[13678]$/.test(word) ? '을' : '를');
let seq = 0;
export const actions = {
first: (api: GridApi<Row>) => {
const id = `memo${++seq}`;
api.addColumn({ id, title: `메모 ${seq}`, width: 90 }, { index: 0 });
say({ ko: `'${id}'${eulReul(id)} 맨 앞에 끼웠어요`, en: `Inserted '${id}' first` });
},
group: (api: GridApi<Row>) => {
const id = `grp${++seq}`;
api.addColumn({ id, title: `근무 ${seq}`, width: 90 }, { groupId: 'work' });
say({
ko: `'${id}'${eulReul(id)} '근무' 그룹에 넣었어요`,
en: `Added '${id}' to the Work group`,
});
},
fill: (api: GridApi<Row>) => {
const id = `bonus${++seq}`;
api.addColumn(
{
id,
title: '보너스',
kind: 'number',
width: 100,
defaultValue: (row: Row) => row.salary / 10,
},
{ fill: true },
);
say({
ko: `'${id}'${eulReul(id)} 더하고 기존 행에 보너스를 채웠어요`,
en: `Added '${id}' and filled existing rows`,
});
},
remove: (api: GridApi<Row>) => {
const last = api.getColumns().at(-1);
if (last === undefined || api.getColumns().length <= 2)
return say({ ko: '더 빼지 않아요', en: 'Keeping at least 2 columns' });
api.removeColumn(last.id);
say({ ko: `'${last.id}'${eulReul(last.id)} 뺐어요`, en: `Removed '${last.id}'` });
},
changes: (api: GridApi<Row>) => {
say({
ko: `더한 컬럼: ${api.getAddedColumns().join(', ') || '없음'} / 뺀 컬럼: ${api.getRemovedColumns().join(', ') || '없음'}`,
en: `Added: ${api.getAddedColumns().join(', ') || 'none'} / Removed: ${api.getRemovedColumns().join(', ') || 'none'}`,
});
},
};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="first">Insert first</button>
<button type="button" id="group">Add to group</button>
<button type="button" id="fill">Add with fill</button>
<button type="button" id="remove">Remove last</button>
<button type="button" id="changes">Changes</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('first').addEventListener('click', () => actions.first(api));
document.getElementById('group').addEventListener('click', () => actions.group(api));
document.getElementById('fill').addEventListener('click', () => actions.fill(api));
document.getElementById('remove').addEventListener('click', () => actions.remove(api));
document.getElementById('changes').addEventListener('click', () => actions.changes(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: 'work', title: 'Work', children: ['team', 'city'] }],
};
export function setup(_api, log) {
say = log;
return () => { };
}
let seq = 0;
export const actions = {
first: (api) => {
const id = `memo${++seq}`;
api.addColumn({ id, title: `Memo ${seq}`, width: 90 }, { index: 0 });
say(`Inserted '${id}' first`);
},
group: (api) => {
const id = `grp${++seq}`;
api.addColumn({ id, title: `Work ${seq}`, width: 90 }, { groupId: 'work' });
say(`Added '${id}' to the Work group`);
},
fill: (api) => {
const id = `bonus${++seq}`;
api.addColumn({
id,
title: 'Bonus',
kind: 'number',
width: 100,
defaultValue: (row) => row.salary / 10,
}, { fill: true });
say(`Added '${id}' and filled existing rows`);
},
remove: (api) => {
const last = api.getColumns().at(-1);
if (last === undefined || api.getColumns().length <= 2)
return say('Keeping at least 2 columns');
api.removeColumn(last.id);
say(`Removed '${last.id}'`);
},
changes: (api) => {
say(`Added: ${api.getAddedColumns().join(', ') || 'none'} / Removed: ${api.getRemovedColumns().join(', ') || 'none'}`);
},
};<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Insert a single column</title>
</head>
<body>
<div class="toolbar">
<button type="button" id="first">Insert first</button>
<button type="button" id="group">Add to group</button>
<button type="button" id="fill">Add with fill</button>
<button type="button" id="remove">Remove last</button>
<button type="button" id="changes">Changes</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: 'work', title: 'Work', children: ['team', 'city'] }],
};
function setup(_api, log) {
say = log;
return () => { };
}
let seq = 0;
const actions = {
first: (api) => {
const id = `memo${++seq}`;
api.addColumn({ id, title: `Memo ${seq}`, width: 90 }, { index: 0 });
say(`Inserted '${id}' first`);
},
group: (api) => {
const id = `grp${++seq}`;
api.addColumn({ id, title: `Work ${seq}`, width: 90 }, { groupId: 'work' });
say(`Added '${id}' to the Work group`);
},
fill: (api) => {
const id = `bonus${++seq}`;
api.addColumn({
id,
title: 'Bonus',
kind: 'number',
width: 100,
defaultValue: (row) => row.salary / 10,
}, { fill: true });
say(`Added '${id}' and filled existing rows`);
},
remove: (api) => {
const last = api.getColumns().at(-1);
if (last === undefined || api.getColumns().length <= 2)
return say('Keeping at least 2 columns');
api.removeColumn(last.id);
say(`Removed '${last.id}'`);
},
changes: (api) => {
say(`Added: ${api.getAddedColumns().join(', ') || 'none'} / Removed: ${api.getRemovedColumns().join(', ') || 'none'}`);
},
};
options.ariaLabel = "Insert a single column";
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('first').addEventListener('click', () => actions.first(api));
document.getElementById('group').addEventListener('click', () => actions.group(api));
document.getElementById('fill').addEventListener('click', () => actions.fill(api));
document.getElementById('remove').addEventListener('click', () => actions.remove(api));
document.getElementById('changes').addEventListener('click', () => actions.changes(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.first(api)}
>Insert first</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.group(api)}
>Add to group</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.fill(api)}
>Add with fill</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.remove(api)}
>Remove last</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.changes(api)}
>Changes</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: 'work', title: 'Work', children: ['team', 'city'] }],
};
export function setup(_api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
return () => {};
}
let seq = 0;
export const actions = {
first: (api: GridApi<Row>) => {
const id = `memo${++seq}`;
api.addColumn({ id, title: `Memo ${seq}`, width: 90 }, { index: 0 });
say(`Inserted '${id}' first`);
},
group: (api: GridApi<Row>) => {
const id = `grp${++seq}`;
api.addColumn({ id, title: `Work ${seq}`, width: 90 }, { groupId: 'work' });
say(`Added '${id}' to the Work group`);
},
fill: (api: GridApi<Row>) => {
const id = `bonus${++seq}`;
api.addColumn(
{
id,
title: 'Bonus',
kind: 'number',
width: 100,
defaultValue: (row: Row) => row.salary / 10,
},
{ fill: true },
);
say(`Added '${id}' and filled existing rows`);
},
remove: (api: GridApi<Row>) => {
const last = api.getColumns().at(-1);
if (last === undefined || api.getColumns().length <= 2)
return say('Keeping at least 2 columns');
api.removeColumn(last.id);
say(`Removed '${last.id}'`);
},
changes: (api: GridApi<Row>) => {
say(
`Added: ${api.getAddedColumns().join(', ') || 'none'} / Removed: ${api.getRemovedColumns().join(', ') || 'none'}`,
);
},
};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.first(api)">Insert first</button>
<button type="button" :disabled="!api" @click="api && actions.group(api)">Add to group</button>
<button type="button" :disabled="!api" @click="api && actions.fill(api)">Add with fill</button>
<button type="button" :disabled="!api" @click="api && actions.remove(api)">Remove last</button>
<button type="button" :disabled="!api" @click="api && actions.changes(api)">Changes</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: 'work', title: 'Work', children: ['team', 'city'] }],
};
export function setup(_api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
return () => {};
}
let seq = 0;
export const actions = {
first: (api: GridApi<Row>) => {
const id = `memo${++seq}`;
api.addColumn({ id, title: `Memo ${seq}`, width: 90 }, { index: 0 });
say(`Inserted '${id}' first`);
},
group: (api: GridApi<Row>) => {
const id = `grp${++seq}`;
api.addColumn({ id, title: `Work ${seq}`, width: 90 }, { groupId: 'work' });
say(`Added '${id}' to the Work group`);
},
fill: (api: GridApi<Row>) => {
const id = `bonus${++seq}`;
api.addColumn(
{
id,
title: 'Bonus',
kind: 'number',
width: 100,
defaultValue: (row: Row) => row.salary / 10,
},
{ fill: true },
);
say(`Added '${id}' and filled existing rows`);
},
remove: (api: GridApi<Row>) => {
const last = api.getColumns().at(-1);
if (last === undefined || api.getColumns().length <= 2)
return say('Keeping at least 2 columns');
api.removeColumn(last.id);
say(`Removed '${last.id}'`);
},
changes: (api: GridApi<Row>) => {
say(
`Added: ${api.getAddedColumns().join(', ') || 'none'} / Removed: ${api.getRemovedColumns().join(', ') || 'none'}`,
);
},
};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.first(api)"
>Insert first</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.group(api)"
>Add to group</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.fill(api)"
>Add with fill</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.remove(api)"
>Remove last</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.changes(api)"
>Changes</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: 'work', title: 'Work', children: ['team', 'city'] }],
};
export function setup(_api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
return () => {};
}
let seq = 0;
export const actions = {
first: (api: GridApi<Row>) => {
const id = `memo${++seq}`;
api.addColumn({ id, title: `Memo ${seq}`, width: 90 }, { index: 0 });
say(`Inserted '${id}' first`);
},
group: (api: GridApi<Row>) => {
const id = `grp${++seq}`;
api.addColumn({ id, title: `Work ${seq}`, width: 90 }, { groupId: 'work' });
say(`Added '${id}' to the Work group`);
},
fill: (api: GridApi<Row>) => {
const id = `bonus${++seq}`;
api.addColumn(
{
id,
title: 'Bonus',
kind: 'number',
width: 100,
defaultValue: (row: Row) => row.salary / 10,
},
{ fill: true },
);
say(`Added '${id}' and filled existing rows`);
},
remove: (api: GridApi<Row>) => {
const last = api.getColumns().at(-1);
if (last === undefined || api.getColumns().length <= 2)
return say('Keeping at least 2 columns');
api.removeColumn(last.id);
say(`Removed '${last.id}'`);
},
changes: (api: GridApi<Row>) => {
say(
`Added: ${api.getAddedColumns().join(', ') || 'none'} / Removed: ${api.getRemovedColumns().join(', ') || 'none'}`,
);
},
};