컬럼 숨김·이동·고정 잠그기Lock hiding, moving and pinning
locked로 컬럼마다 숨김(visible)·이동(position)·고정(pin)을 막아요. 메뉴 항목은 사라지지 않고 흐려지고, API는 invalid-option을 던지고, 저장한 상태를 복원해도 잠긴 속성은 지금 그대로예요.locked blocks hiding (visible), moving (position) and pinning (pin) per column. Menu items are dimmed instead of removed, the API throws invalid-option, and restoring a saved state keeps locked properties as they are.
코드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="hide">이름 숨겨 보기</button>
<button type="button" id="move">이름 옮겨 보기</button>
<button type="button" id="pin">사번 고정해 보기</button>
<button type="button" id="restore">저장본 복원</button>
</div>
<div id="grid" style="height: 260px"></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('hide').addEventListener('click', () => actions.hide(api));
document.getElementById('move').addEventListener('click', () => actions.move(api));
document.getElementById('pin').addEventListener('click', () => actions.pin(api));
document.getElementById('restore').addEventListener('click', () => actions.restore(api));const ROWS = [
{ id: 1001, name: '김민준', team: '개발팀', city: '서울', salary: 6200, bonus: 620 },
{ id: 1002, name: '이서연', team: '디자인팀', city: '부산', salary: 4800, bonus: 480 },
{ id: 1003, name: '박지호', team: '영업팀', city: '대구', salary: 7100, bonus: 710 },
{ id: 1004, name: '최유나', team: '인사팀', city: '서울', salary: 3900, bonus: 390 },
];
let say = () => { };
export function setup(_api, log) {
say = log;
return () => { };
}
const attempt = (run, ok) => {
try {
run();
say(ok);
}
catch (error) {
say({
ko: `막혔어요: ${error.message}`,
en: `Refused: ${error.message}`,
});
}
};
const COLUMNS = [
{ id: 'id', title: '사번', width: 90, align: 'end', locked: true },
{ id: 'name', title: '이름', width: 120, locked: { position: true, visible: true } },
{ id: 'team', title: '팀', width: 120 },
{ id: 'city', title: '근무지', width: 110 },
{ id: 'salary', title: '연봉(만원)', kind: 'number', width: 120, align: 'end' },
];
export const options = {
columns: COLUMNS,
rows: ROWS,
rowKey: 'id',
columnMenu: true,
};
export const actions = {
hide: (api) => attempt(() => api.setColumnVisible('name', false), { ko: '이름을 숨겼어요', en: 'Hid Name' }),
move: (api) => attempt(() => api.moveColumn('name', 4), { ko: '이름을 옮겼어요', en: 'Moved Name' }),
pin: (api) => attempt(() => api.pinColumn('id', 'start'), { ko: '사번을 고정했어요', en: 'Pinned Id' }),
restore: (api) => {
api.setColumnState([
{ id: 'team', width: 140, hidden: false, pinned: null },
{ id: 'city', width: 100, hidden: false, pinned: null },
{ id: 'salary', width: 130, hidden: false, pinned: null },
{ id: 'name', width: 150, hidden: true, pinned: null },
{ id: 'id', width: 90, hidden: true, pinned: 'end' },
]);
say({
ko: '저장본을 적용했어요. 이름·사번의 숨김·위치·고정은 그대로고 폭만 바뀌었어요',
en: 'Applied the saved state. Name and Id keep hidden, position and pin; only widths changed',
});
},
};<!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="hide">이름 숨겨 보기</button>
<button type="button" id="move">이름 옮겨 보기</button>
<button type="button" id="pin">사번 고정해 보기</button>
<button type="button" id="restore">저장본 복원</button>
</div>
<div id="grid" style="height: 260px"></div>
<ul id="log" aria-live="polite"></ul>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script>
const ROWS = [
{ id: 1001, name: '김민준', team: '개발팀', city: '서울', salary: 6200, bonus: 620 },
{ id: 1002, name: '이서연', team: '디자인팀', city: '부산', salary: 4800, bonus: 480 },
{ id: 1003, name: '박지호', team: '영업팀', city: '대구', salary: 7100, bonus: 710 },
{ id: 1004, name: '최유나', team: '인사팀', city: '서울', salary: 3900, bonus: 390 },
];
let say = () => { };
function setup(_api, log) {
say = log;
return () => { };
}
const attempt = (run, ok) => {
try {
run();
say(ok);
}
catch (error) {
say({
ko: `막혔어요: ${error.message}`,
en: `Refused: ${error.message}`,
});
}
};
const COLUMNS = [
{ id: 'id', title: '사번', width: 90, align: 'end', locked: true },
{ id: 'name', title: '이름', width: 120, locked: { position: true, visible: true } },
{ id: 'team', title: '팀', width: 120 },
{ id: 'city', title: '근무지', width: 110 },
{ id: 'salary', title: '연봉(만원)', kind: 'number', width: 120, align: 'end' },
];
const options = {
columns: COLUMNS,
rows: ROWS,
rowKey: 'id',
columnMenu: true,
};
const actions = {
hide: (api) => attempt(() => api.setColumnVisible('name', false), { ko: '이름을 숨겼어요', en: 'Hid Name' }),
move: (api) => attempt(() => api.moveColumn('name', 4), { ko: '이름을 옮겼어요', en: 'Moved Name' }),
pin: (api) => attempt(() => api.pinColumn('id', 'start'), { ko: '사번을 고정했어요', en: 'Pinned Id' }),
restore: (api) => {
api.setColumnState([
{ id: 'team', width: 140, hidden: false, pinned: null },
{ id: 'city', width: 100, hidden: false, pinned: null },
{ id: 'salary', width: 130, hidden: false, pinned: null },
{ id: 'name', width: 150, hidden: true, pinned: null },
{ id: 'id', width: 90, hidden: true, pinned: 'end' },
]);
say({
ko: '저장본을 적용했어요. 이름·사번의 숨김·위치·고정은 그대로고 폭만 바뀌었어요',
en: 'Applied the saved state. Name and Id keep hidden, position and pin; only widths changed',
});
},
};
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('hide').addEventListener('click', () => actions.hide(api));
document.getElementById('move').addEventListener('click', () => actions.move(api));
document.getElementById('pin').addEventListener('click', () => actions.pin(api));
document.getElementById('restore').addEventListener('click', () => actions.restore(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.hide(api)}
>이름 숨겨 보기</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.move(api)}
>이름 옮겨 보기</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.pin(api)}
>사번 고정해 보기</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.restore(api)}
>저장본 복원</button>
</div>
<Grid style={{ height: 260 }} 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;
bonus: number;
}
const ROWS: Row[] = [
{ id: 1001, name: '김민준', team: '개발팀', city: '서울', salary: 6200, bonus: 620 },
{ id: 1002, name: '이서연', team: '디자인팀', city: '부산', salary: 4800, bonus: 480 },
{ id: 1003, name: '박지호', team: '영업팀', city: '대구', salary: 7100, bonus: 710 },
{ id: 1004, name: '최유나', team: '인사팀', city: '서울', salary: 3900, bonus: 390 },
];
let say: (message: LogText) => void = () => {};
export function setup(_api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
return () => {};
}
const attempt = (run: () => void, ok: LogText): void => {
try {
run();
say(ok);
} catch (error) {
say({
ko: `막혔어요: ${(error as Error).message}`,
en: `Refused: ${(error as Error).message}`,
});
}
};
const COLUMNS: ColumnDef<Row>[] = [
{ id: 'id', title: '사번', width: 90, align: 'end', locked: true },
{ id: 'name', title: '이름', width: 120, locked: { position: true, visible: true } },
{ id: 'team', title: '팀', width: 120 },
{ id: 'city', title: '근무지', width: 110 },
{ id: 'salary', title: '연봉(만원)', kind: 'number', width: 120, align: 'end' },
];
export const options: GridOptions<Row> = {
columns: COLUMNS,
rows: ROWS,
rowKey: 'id',
columnMenu: true,
};
export const actions = {
hide: (api: GridApi<Row>) =>
attempt(() => api.setColumnVisible('name', false), { ko: '이름을 숨겼어요', en: 'Hid Name' }),
move: (api: GridApi<Row>) =>
attempt(() => api.moveColumn('name', 4), { ko: '이름을 옮겼어요', en: 'Moved Name' }),
pin: (api: GridApi<Row>) =>
attempt(() => api.pinColumn('id', 'start'), { ko: '사번을 고정했어요', en: 'Pinned Id' }),
restore: (api: GridApi<Row>) => {
api.setColumnState([
{ id: 'team', width: 140, hidden: false, pinned: null },
{ id: 'city', width: 100, hidden: false, pinned: null },
{ id: 'salary', width: 130, hidden: false, pinned: null },
{ id: 'name', width: 150, hidden: true, pinned: null },
{ id: 'id', width: 90, hidden: true, pinned: 'end' },
]);
say({
ko: '저장본을 적용했어요. 이름·사번의 숨김·위치·고정은 그대로고 폭만 바뀌었어요',
en: 'Applied the saved state. Name and Id keep hidden, position and pin; only widths changed',
});
},
};버튼을 누르면 이 예제의 코드가 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.hide(api)">이름 숨겨 보기</button>
<button type="button" :disabled="!api" @click="api && actions.move(api)">이름 옮겨 보기</button>
<button type="button" :disabled="!api" @click="api && actions.pin(api)">사번 고정해 보기</button>
<button type="button" :disabled="!api" @click="api && actions.restore(api)">저장본 복원</button>
</div>
<Grid style="height: 260px" :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;
bonus: number;
}
const ROWS: Row[] = [
{ id: 1001, name: '김민준', team: '개발팀', city: '서울', salary: 6200, bonus: 620 },
{ id: 1002, name: '이서연', team: '디자인팀', city: '부산', salary: 4800, bonus: 480 },
{ id: 1003, name: '박지호', team: '영업팀', city: '대구', salary: 7100, bonus: 710 },
{ id: 1004, name: '최유나', team: '인사팀', city: '서울', salary: 3900, bonus: 390 },
];
let say: (message: LogText) => void = () => {};
export function setup(_api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
return () => {};
}
const attempt = (run: () => void, ok: LogText): void => {
try {
run();
say(ok);
} catch (error) {
say({
ko: `막혔어요: ${(error as Error).message}`,
en: `Refused: ${(error as Error).message}`,
});
}
};
const COLUMNS: ColumnDef<Row>[] = [
{ id: 'id', title: '사번', width: 90, align: 'end', locked: true },
{ id: 'name', title: '이름', width: 120, locked: { position: true, visible: true } },
{ id: 'team', title: '팀', width: 120 },
{ id: 'city', title: '근무지', width: 110 },
{ id: 'salary', title: '연봉(만원)', kind: 'number', width: 120, align: 'end' },
];
export const options: GridOptions<Row> = {
columns: COLUMNS,
rows: ROWS,
rowKey: 'id',
columnMenu: true,
};
export const actions = {
hide: (api: GridApi<Row>) =>
attempt(() => api.setColumnVisible('name', false), { ko: '이름을 숨겼어요', en: 'Hid Name' }),
move: (api: GridApi<Row>) =>
attempt(() => api.moveColumn('name', 4), { ko: '이름을 옮겼어요', en: 'Moved Name' }),
pin: (api: GridApi<Row>) =>
attempt(() => api.pinColumn('id', 'start'), { ko: '사번을 고정했어요', en: 'Pinned Id' }),
restore: (api: GridApi<Row>) => {
api.setColumnState([
{ id: 'team', width: 140, hidden: false, pinned: null },
{ id: 'city', width: 100, hidden: false, pinned: null },
{ id: 'salary', width: 130, hidden: false, pinned: null },
{ id: 'name', width: 150, hidden: true, pinned: null },
{ id: 'id', width: 90, hidden: true, pinned: 'end' },
]);
say({
ko: '저장본을 적용했어요. 이름·사번의 숨김·위치·고정은 그대로고 폭만 바뀌었어요',
en: 'Applied the saved state. Name and Id keep hidden, position and pin; only widths changed',
});
},
};버튼을 누르면 이 예제의 코드가 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.hide(api)"
>이름 숨겨 보기</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.move(api)"
>이름 옮겨 보기</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.pin(api)"
>사번 고정해 보기</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.restore(api)"
>저장본 복원</button>
</div>
<mx-grid style="height: 260px" [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;
bonus: number;
}
const ROWS: Row[] = [
{ id: 1001, name: '김민준', team: '개발팀', city: '서울', salary: 6200, bonus: 620 },
{ id: 1002, name: '이서연', team: '디자인팀', city: '부산', salary: 4800, bonus: 480 },
{ id: 1003, name: '박지호', team: '영업팀', city: '대구', salary: 7100, bonus: 710 },
{ id: 1004, name: '최유나', team: '인사팀', city: '서울', salary: 3900, bonus: 390 },
];
let say: (message: LogText) => void = () => {};
export function setup(_api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
return () => {};
}
const attempt = (run: () => void, ok: LogText): void => {
try {
run();
say(ok);
} catch (error) {
say({
ko: `막혔어요: ${(error as Error).message}`,
en: `Refused: ${(error as Error).message}`,
});
}
};
const COLUMNS: ColumnDef<Row>[] = [
{ id: 'id', title: '사번', width: 90, align: 'end', locked: true },
{ id: 'name', title: '이름', width: 120, locked: { position: true, visible: true } },
{ id: 'team', title: '팀', width: 120 },
{ id: 'city', title: '근무지', width: 110 },
{ id: 'salary', title: '연봉(만원)', kind: 'number', width: 120, align: 'end' },
];
export const options: GridOptions<Row> = {
columns: COLUMNS,
rows: ROWS,
rowKey: 'id',
columnMenu: true,
};
export const actions = {
hide: (api: GridApi<Row>) =>
attempt(() => api.setColumnVisible('name', false), { ko: '이름을 숨겼어요', en: 'Hid Name' }),
move: (api: GridApi<Row>) =>
attempt(() => api.moveColumn('name', 4), { ko: '이름을 옮겼어요', en: 'Moved Name' }),
pin: (api: GridApi<Row>) =>
attempt(() => api.pinColumn('id', 'start'), { ko: '사번을 고정했어요', en: 'Pinned Id' }),
restore: (api: GridApi<Row>) => {
api.setColumnState([
{ id: 'team', width: 140, hidden: false, pinned: null },
{ id: 'city', width: 100, hidden: false, pinned: null },
{ id: 'salary', width: 130, hidden: false, pinned: null },
{ id: 'name', width: 150, hidden: true, pinned: null },
{ id: 'id', width: 90, hidden: true, pinned: 'end' },
]);
say({
ko: '저장본을 적용했어요. 이름·사번의 숨김·위치·고정은 그대로고 폭만 바뀌었어요',
en: 'Applied the saved state. Name and Id keep hidden, position and pin; only widths changed',
});
},
};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="hide">Try hiding Name</button>
<button type="button" id="move">Try moving Name</button>
<button type="button" id="pin">Try pinning Emp ID</button>
<button type="button" id="restore">Restore saved state</button>
</div>
<div id="grid" style="height: 260px"></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('hide').addEventListener('click', () => actions.hide(api));
document.getElementById('move').addEventListener('click', () => actions.move(api));
document.getElementById('pin').addEventListener('click', () => actions.pin(api));
document.getElementById('restore').addEventListener('click', () => actions.restore(api));const ROWS = [
{ id: 1001, name: 'Liam Carter', team: 'Dev', city: 'Seattle', salary: 62000, bonus: 6200 },
{ id: 1002, name: 'Emma Stone', team: 'Design', city: 'Boston', salary: 48000, bonus: 4800 },
{ id: 1003, name: 'Noah Hayes', team: 'Sales', city: 'Denver', salary: 71000, bonus: 7100 },
{ id: 1004, name: 'Olivia Reed', team: 'HR', city: 'Seattle', salary: 39000, bonus: 3900 },
];
let say = () => { };
export function setup(_api, log) {
say = log;
return () => { };
}
const attempt = (run, ok) => {
try {
run();
say(ok);
}
catch (error) {
say(`Refused: ${error.message}`);
}
};
const COLUMNS = [
{ id: 'id', title: 'Emp ID', width: 90, align: 'end', locked: true },
{ id: 'name', title: 'Name', width: 120, locked: { position: true, visible: true } },
{ id: 'team', title: 'Team', width: 120 },
{ id: 'city', title: 'Office', width: 110 },
{ id: 'salary', title: 'Salary ($)', kind: 'number', width: 120, align: 'end' },
];
export const options = {
columns: COLUMNS,
rows: ROWS,
rowKey: 'id',
columnMenu: true,
};
export const actions = {
hide: (api) => attempt(() => api.setColumnVisible('name', false), 'Hid Name'),
move: (api) => attempt(() => api.moveColumn('name', 4), 'Moved Name'),
pin: (api) => attempt(() => api.pinColumn('id', 'start'), 'Pinned Id'),
restore: (api) => {
api.setColumnState([
{ id: 'team', width: 140, hidden: false, pinned: null },
{ id: 'city', width: 100, hidden: false, pinned: null },
{ id: 'salary', width: 130, hidden: false, pinned: null },
{ id: 'name', width: 150, hidden: true, pinned: null },
{ id: 'id', width: 90, hidden: true, pinned: 'end' },
]);
say('Applied the saved state. Name and Id keep hidden, position and pin; only widths changed');
},
};<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Lock hiding, moving and pinning</title>
</head>
<body>
<div class="toolbar">
<button type="button" id="hide">Try hiding Name</button>
<button type="button" id="move">Try moving Name</button>
<button type="button" id="pin">Try pinning Emp ID</button>
<button type="button" id="restore">Restore saved state</button>
</div>
<div id="grid" style="height: 260px"></div>
<ul id="log" aria-live="polite"></ul>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script>
const ROWS = [
{ id: 1001, name: 'Liam Carter', team: 'Dev', city: 'Seattle', salary: 62000, bonus: 6200 },
{ id: 1002, name: 'Emma Stone', team: 'Design', city: 'Boston', salary: 48000, bonus: 4800 },
{ id: 1003, name: 'Noah Hayes', team: 'Sales', city: 'Denver', salary: 71000, bonus: 7100 },
{ id: 1004, name: 'Olivia Reed', team: 'HR', city: 'Seattle', salary: 39000, bonus: 3900 },
];
let say = () => { };
function setup(_api, log) {
say = log;
return () => { };
}
const attempt = (run, ok) => {
try {
run();
say(ok);
}
catch (error) {
say(`Refused: ${error.message}`);
}
};
const COLUMNS = [
{ id: 'id', title: 'Emp ID', width: 90, align: 'end', locked: true },
{ id: 'name', title: 'Name', width: 120, locked: { position: true, visible: true } },
{ id: 'team', title: 'Team', width: 120 },
{ id: 'city', title: 'Office', width: 110 },
{ id: 'salary', title: 'Salary ($)', kind: 'number', width: 120, align: 'end' },
];
const options = {
columns: COLUMNS,
rows: ROWS,
rowKey: 'id',
columnMenu: true,
};
const actions = {
hide: (api) => attempt(() => api.setColumnVisible('name', false), 'Hid Name'),
move: (api) => attempt(() => api.moveColumn('name', 4), 'Moved Name'),
pin: (api) => attempt(() => api.pinColumn('id', 'start'), 'Pinned Id'),
restore: (api) => {
api.setColumnState([
{ id: 'team', width: 140, hidden: false, pinned: null },
{ id: 'city', width: 100, hidden: false, pinned: null },
{ id: 'salary', width: 130, hidden: false, pinned: null },
{ id: 'name', width: 150, hidden: true, pinned: null },
{ id: 'id', width: 90, hidden: true, pinned: 'end' },
]);
say('Applied the saved state. Name and Id keep hidden, position and pin; only widths changed');
},
};
options.ariaLabel = "Lock hiding, moving and pinning";
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('hide').addEventListener('click', () => actions.hide(api));
document.getElementById('move').addEventListener('click', () => actions.move(api));
document.getElementById('pin').addEventListener('click', () => actions.pin(api));
document.getElementById('restore').addEventListener('click', () => actions.restore(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.hide(api)}
>Try hiding Name</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.move(api)}
>Try moving Name</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.pin(api)}
>Try pinning Emp ID</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.restore(api)}
>Restore saved state</button>
</div>
<Grid style={{ height: 260 }} 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;
bonus: number;
}
const ROWS: Row[] = [
{ id: 1001, name: 'Liam Carter', team: 'Dev', city: 'Seattle', salary: 62000, bonus: 6200 },
{ id: 1002, name: 'Emma Stone', team: 'Design', city: 'Boston', salary: 48000, bonus: 4800 },
{ id: 1003, name: 'Noah Hayes', team: 'Sales', city: 'Denver', salary: 71000, bonus: 7100 },
{ id: 1004, name: 'Olivia Reed', team: 'HR', city: 'Seattle', salary: 39000, bonus: 3900 },
];
let say: (message: LogText) => void = () => {};
export function setup(_api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
return () => {};
}
const attempt = (run: () => void, ok: LogText): void => {
try {
run();
say(ok);
} catch (error) {
say(`Refused: ${(error as Error).message}`);
}
};
const COLUMNS: ColumnDef<Row>[] = [
{ id: 'id', title: 'Emp ID', width: 90, align: 'end', locked: true },
{ id: 'name', title: 'Name', width: 120, locked: { position: true, visible: true } },
{ id: 'team', title: 'Team', width: 120 },
{ id: 'city', title: 'Office', width: 110 },
{ id: 'salary', title: 'Salary ($)', kind: 'number', width: 120, align: 'end' },
];
export const options: GridOptions<Row> = {
columns: COLUMNS,
rows: ROWS,
rowKey: 'id',
columnMenu: true,
};
export const actions = {
hide: (api: GridApi<Row>) => attempt(() => api.setColumnVisible('name', false), 'Hid Name'),
move: (api: GridApi<Row>) => attempt(() => api.moveColumn('name', 4), 'Moved Name'),
pin: (api: GridApi<Row>) => attempt(() => api.pinColumn('id', 'start'), 'Pinned Id'),
restore: (api: GridApi<Row>) => {
api.setColumnState([
{ id: 'team', width: 140, hidden: false, pinned: null },
{ id: 'city', width: 100, hidden: false, pinned: null },
{ id: 'salary', width: 130, hidden: false, pinned: null },
{ id: 'name', width: 150, hidden: true, pinned: null },
{ id: 'id', width: 90, hidden: true, pinned: 'end' },
]);
say('Applied the saved state. Name and Id keep hidden, position and pin; only widths changed');
},
};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.hide(api)">Try hiding Name</button>
<button type="button" :disabled="!api" @click="api && actions.move(api)">Try moving Name</button>
<button type="button" :disabled="!api" @click="api && actions.pin(api)">Try pinning Emp ID</button>
<button type="button" :disabled="!api" @click="api && actions.restore(api)">Restore saved state</button>
</div>
<Grid style="height: 260px" :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;
bonus: number;
}
const ROWS: Row[] = [
{ id: 1001, name: 'Liam Carter', team: 'Dev', city: 'Seattle', salary: 62000, bonus: 6200 },
{ id: 1002, name: 'Emma Stone', team: 'Design', city: 'Boston', salary: 48000, bonus: 4800 },
{ id: 1003, name: 'Noah Hayes', team: 'Sales', city: 'Denver', salary: 71000, bonus: 7100 },
{ id: 1004, name: 'Olivia Reed', team: 'HR', city: 'Seattle', salary: 39000, bonus: 3900 },
];
let say: (message: LogText) => void = () => {};
export function setup(_api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
return () => {};
}
const attempt = (run: () => void, ok: LogText): void => {
try {
run();
say(ok);
} catch (error) {
say(`Refused: ${(error as Error).message}`);
}
};
const COLUMNS: ColumnDef<Row>[] = [
{ id: 'id', title: 'Emp ID', width: 90, align: 'end', locked: true },
{ id: 'name', title: 'Name', width: 120, locked: { position: true, visible: true } },
{ id: 'team', title: 'Team', width: 120 },
{ id: 'city', title: 'Office', width: 110 },
{ id: 'salary', title: 'Salary ($)', kind: 'number', width: 120, align: 'end' },
];
export const options: GridOptions<Row> = {
columns: COLUMNS,
rows: ROWS,
rowKey: 'id',
columnMenu: true,
};
export const actions = {
hide: (api: GridApi<Row>) => attempt(() => api.setColumnVisible('name', false), 'Hid Name'),
move: (api: GridApi<Row>) => attempt(() => api.moveColumn('name', 4), 'Moved Name'),
pin: (api: GridApi<Row>) => attempt(() => api.pinColumn('id', 'start'), 'Pinned Id'),
restore: (api: GridApi<Row>) => {
api.setColumnState([
{ id: 'team', width: 140, hidden: false, pinned: null },
{ id: 'city', width: 100, hidden: false, pinned: null },
{ id: 'salary', width: 130, hidden: false, pinned: null },
{ id: 'name', width: 150, hidden: true, pinned: null },
{ id: 'id', width: 90, hidden: true, pinned: 'end' },
]);
say('Applied the saved state. Name and Id keep hidden, position and pin; only widths changed');
},
};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.hide(api)"
>Try hiding Name</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.move(api)"
>Try moving Name</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.pin(api)"
>Try pinning Emp ID</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.restore(api)"
>Restore saved state</button>
</div>
<mx-grid style="height: 260px" [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;
bonus: number;
}
const ROWS: Row[] = [
{ id: 1001, name: 'Liam Carter', team: 'Dev', city: 'Seattle', salary: 62000, bonus: 6200 },
{ id: 1002, name: 'Emma Stone', team: 'Design', city: 'Boston', salary: 48000, bonus: 4800 },
{ id: 1003, name: 'Noah Hayes', team: 'Sales', city: 'Denver', salary: 71000, bonus: 7100 },
{ id: 1004, name: 'Olivia Reed', team: 'HR', city: 'Seattle', salary: 39000, bonus: 3900 },
];
let say: (message: LogText) => void = () => {};
export function setup(_api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
return () => {};
}
const attempt = (run: () => void, ok: LogText): void => {
try {
run();
say(ok);
} catch (error) {
say(`Refused: ${(error as Error).message}`);
}
};
const COLUMNS: ColumnDef<Row>[] = [
{ id: 'id', title: 'Emp ID', width: 90, align: 'end', locked: true },
{ id: 'name', title: 'Name', width: 120, locked: { position: true, visible: true } },
{ id: 'team', title: 'Team', width: 120 },
{ id: 'city', title: 'Office', width: 110 },
{ id: 'salary', title: 'Salary ($)', kind: 'number', width: 120, align: 'end' },
];
export const options: GridOptions<Row> = {
columns: COLUMNS,
rows: ROWS,
rowKey: 'id',
columnMenu: true,
};
export const actions = {
hide: (api: GridApi<Row>) => attempt(() => api.setColumnVisible('name', false), 'Hid Name'),
move: (api: GridApi<Row>) => attempt(() => api.moveColumn('name', 4), 'Moved Name'),
pin: (api: GridApi<Row>) => attempt(() => api.pinColumn('id', 'start'), 'Pinned Id'),
restore: (api: GridApi<Row>) => {
api.setColumnState([
{ id: 'team', width: 140, hidden: false, pinned: null },
{ id: 'city', width: 100, hidden: false, pinned: null },
{ id: 'salary', width: 130, hidden: false, pinned: null },
{ id: 'name', width: 150, hidden: true, pinned: null },
{ id: 'id', width: 90, hidden: true, pinned: 'end' },
]);
say('Applied the saved state. Name and Id keep hidden, position and pin; only widths changed');
},
};