컬럼 도구 모음으로 컬럼 숨기고 옮기기Hide and reorder columns with the column toolbar
columnToolbar를 켜면 그리드 위나 아래에 컬럼마다 칩이 하나 생겨요. 칩을 누르면(Space·Enter) 컬럼이 보이거나 숨고, 칩을 끌거나 Alt+←/→를 누르면 컬럼 순서가 바뀌어요. 숨긴 칩은 흐리게 보이고 각 칩은 aria-pressed로 상태를 알려요.Turn on columnToolbar and a strip above or below the grid shows one chip per column. Press a chip (Space or Enter) to hide or show the column, and drag a chip or press Alt+Left/Right to reorder. Hidden chips are dimmed and every chip reports its state with aria-pressed.
코드Code
탭을 골라 코드를 복사하세요. 위 화면은 이 코드를 그대로 실행한 결과예요.Pick a tab and copy the code. The preview above runs exactly this code.
이 화면은 새 모양 옵션을 켠 모양이에요: density: 'spacious', iconStyle: 'soft', motion: true (코드에 없으면 기본 모양으로 보여요)This preview has the new-look options on: density: 'spacious', iconStyle: 'soft', motion: true (without them in your code you get the default look)
버튼을 누르면 이 예제의 코드가 StackBlitz나 CodeSandbox로 전송돼요. 누르기 전에는 아무것도 보내지 않아요.
<div id="app">
<div class="toolbar">
<select aria-label="칩 위치" id="position">
<option value="top" selected>위</option>
<option value="bottom">아래</option>
</select>
<select aria-label="칩 글자" id="labels">
<option value="labels" selected>컬럼 제목 보이기</option>
<option value="icons">아이콘만</option>
</select>
<button type="button" id="showAll">숨긴 컬럼 모두 보이기</button>
</div>
<div id="grid" style="height: 330px"></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('position').addEventListener('change', (event) => actions.position(api, event.target.value));
document.getElementById('labels').addEventListener('change', (event) => actions.labels(api, event.target.value));
document.getElementById('showAll').addEventListener('click', () => actions.showAll(api));const names = ['김서연', '이준호', '박민지', '최도윤', '정하은', '강지후', '윤서아', '임태민'];
const teams = ['개발', '디자인', '영업', '인사'];
const cities = ['서울', '부산', '대구', '인천', '광주'];
// columnToolbar: true면 그리드 위에 컬럼마다 칩이 하나 생겨요. 칩을 누르면 컬럼이 보이거나 숨고,
// 칩을 끌거나 Alt+←/→를 누르면 컬럼 순서가 바뀌어요. 칩 모양은 { position, showLabels }로 정해요.
let toolbar = {
position: 'top',
showLabels: true,
};
export const options = {
columns: [
{ id: 'id', title: '번호', width: 70, align: 'end' },
{ id: 'name', title: '이름', width: 120 },
{ id: 'team', title: '팀', width: 100 },
{ id: 'city', title: '지역', width: 100 },
{ id: 'email', title: '이메일', width: 200 },
{ id: 'joined', title: '입사일', width: 120 },
],
rows: Array.from({ length: 12 }, (_, i) => ({
id: i + 1,
name: names[i % names.length],
team: teams[(i * 3) % teams.length],
city: cities[(i * 2) % cities.length],
email: `user${i + 1}@example.com`,
joined: `2023-${String(1 + (i % 12)).padStart(2, '0')}-${String(3 + i).padStart(2, '0')}`,
})),
rowKey: 'id',
columnToolbar: true,
};
export function setup(api, log) {
toolbar = { position: 'top', showLabels: true };
log({
ko: '칩을 눌러 컬럼을 숨기거나 보이고, 칩을 끌어 순서를 바꿔 보세요.',
en: 'Press a chip to hide or show its column, and drag a chip to reorder.',
});
const offs = [
api.on('columnVisibilityChanged', ({ columnId, hidden }) => log({
ko: `${columnId} 컬럼을 ${hidden ? '숨겼어요' : '보여요'}`,
en: `Column ${columnId} ${hidden ? 'hidden' : 'shown'}`,
})),
api.on('columnMoved', ({ columnId, order }) => log({
ko: `${columnId} 이동 → ${order.join(' · ')}`,
en: `${columnId} moved → ${order.join(' · ')}`,
})),
];
return () => offs.forEach((off) => off());
}
export const actions = {
position: (api, value) => {
toolbar = { ...toolbar, position: value === 'bottom' ? 'bottom' : 'top' };
api.setOptions({ columnToolbar: toolbar });
},
labels: (api, value) => {
toolbar = { ...toolbar, showLabels: value !== 'icons' };
api.setOptions({ columnToolbar: toolbar });
},
showAll: (api) => api.showAllColumns(),
};<!doctype html>
<html lang="ko">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>컬럼 도구 모음으로 컬럼 숨기고 옮기기</title>
</head>
<body>
<div class="toolbar">
<select aria-label="칩 위치" id="position">
<option value="top" selected>위</option>
<option value="bottom">아래</option>
</select>
<select aria-label="칩 글자" id="labels">
<option value="labels" selected>컬럼 제목 보이기</option>
<option value="icons">아이콘만</option>
</select>
<button type="button" id="showAll">숨긴 컬럼 모두 보이기</button>
</div>
<div id="grid" style="height: 330px"></div>
<ul id="log" aria-live="polite"></ul>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script>
const names = ['김서연', '이준호', '박민지', '최도윤', '정하은', '강지후', '윤서아', '임태민'];
const teams = ['개발', '디자인', '영업', '인사'];
const cities = ['서울', '부산', '대구', '인천', '광주'];
// columnToolbar: true면 그리드 위에 컬럼마다 칩이 하나 생겨요. 칩을 누르면 컬럼이 보이거나 숨고,
// 칩을 끌거나 Alt+←/→를 누르면 컬럼 순서가 바뀌어요. 칩 모양은 { position, showLabels }로 정해요.
let toolbar = {
position: 'top',
showLabels: true,
};
const options = {
columns: [
{ id: 'id', title: '번호', width: 70, align: 'end' },
{ id: 'name', title: '이름', width: 120 },
{ id: 'team', title: '팀', width: 100 },
{ id: 'city', title: '지역', width: 100 },
{ id: 'email', title: '이메일', width: 200 },
{ id: 'joined', title: '입사일', width: 120 },
],
rows: Array.from({ length: 12 }, (_, i) => ({
id: i + 1,
name: names[i % names.length],
team: teams[(i * 3) % teams.length],
city: cities[(i * 2) % cities.length],
email: `user${i + 1}@example.com`,
joined: `2023-${String(1 + (i % 12)).padStart(2, '0')}-${String(3 + i).padStart(2, '0')}`,
})),
rowKey: 'id',
columnToolbar: true,
};
function setup(api, log) {
toolbar = { position: 'top', showLabels: true };
log({
ko: '칩을 눌러 컬럼을 숨기거나 보이고, 칩을 끌어 순서를 바꿔 보세요.',
en: 'Press a chip to hide or show its column, and drag a chip to reorder.',
});
const offs = [
api.on('columnVisibilityChanged', ({ columnId, hidden }) => log({
ko: `${columnId} 컬럼을 ${hidden ? '숨겼어요' : '보여요'}`,
en: `Column ${columnId} ${hidden ? 'hidden' : 'shown'}`,
})),
api.on('columnMoved', ({ columnId, order }) => log({
ko: `${columnId} 이동 → ${order.join(' · ')}`,
en: `${columnId} moved → ${order.join(' · ')}`,
})),
];
return () => offs.forEach((off) => off());
}
const actions = {
position: (api, value) => {
toolbar = { ...toolbar, position: value === 'bottom' ? 'bottom' : 'top' };
api.setOptions({ columnToolbar: toolbar });
},
labels: (api, value) => {
toolbar = { ...toolbar, showLabels: value !== 'icons' };
api.setOptions({ columnToolbar: toolbar });
},
showAll: (api) => api.showAllColumns(),
};
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('position').addEventListener('change', (event) => actions.position(api, event.target.value));
document.getElementById('labels').addEventListener('change', (event) => actions.labels(api, event.target.value));
document.getElementById('showAll').addEventListener('click', () => actions.showAll(api));
</script>
</body>
</html>버튼을 누르면 이 예제의 코드가 StackBlitz나 CodeSandbox로 전송돼요. 누르기 전에는 아무것도 보내지 않아요.
import { useEffect } from 'react';
import { Grid, useGridApi } from '@maxgrid/react';
import { actions, options, setup, type Row } from './example';
export function ExampleGrid() {
const [api, gridRef] = useGridApi<Row>();
useEffect(() => (api ? setup(api, console.log) : undefined), [api]);
return (
<>
<div className="toolbar">
<select
aria-label="칩 위치"
disabled={!api}
onChange={(event) => api && actions.position(api, event.target.value)}
>
<option value="top">위</option>
<option value="bottom">아래</option>
</select>
<select defaultValue="top"
aria-label="칩 글자"
disabled={!api}
onChange={(event) => api && actions.labels(api, event.target.value)}
>
<option value="labels">컬럼 제목 보이기</option>
<option value="icons">아이콘만</option>
</select>
<button
type="button"
disabled={!api}
onClick={() => api && actions.showAll(api)}
>숨긴 컬럼 모두 보이기</button>
</div>
<Grid style={{ height: 330 }} ref={gridRef} options={options} />
</>
);
}import type { GridApi, GridOptions } from '@maxgrid/react';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
name: string;
team: string;
city: string;
email: string;
joined: string;
}
const names = ['김서연', '이준호', '박민지', '최도윤', '정하은', '강지후', '윤서아', '임태민'];
const teams = ['개발', '디자인', '영업', '인사'];
const cities = ['서울', '부산', '대구', '인천', '광주'];
// columnToolbar: true면 그리드 위에 컬럼마다 칩이 하나 생겨요. 칩을 누르면 컬럼이 보이거나 숨고,
// 칩을 끌거나 Alt+←/→를 누르면 컬럼 순서가 바뀌어요. 칩 모양은 { position, showLabels }로 정해요.
let toolbar: { position: 'top' | 'bottom'; showLabels: boolean } = {
position: 'top',
showLabels: true,
};
export const options: GridOptions<Row> = {
columns: [
{ id: 'id', title: '번호', width: 70, align: 'end' },
{ id: 'name', title: '이름', width: 120 },
{ id: 'team', title: '팀', width: 100 },
{ id: 'city', title: '지역', width: 100 },
{ id: 'email', title: '이메일', width: 200 },
{ id: 'joined', title: '입사일', width: 120 },
],
rows: Array.from({ length: 12 }, (_, i) => ({
id: i + 1,
name: names[i % names.length],
team: teams[(i * 3) % teams.length],
city: cities[(i * 2) % cities.length],
email: `user${i + 1}@example.com`,
joined: `2023-${String(1 + (i % 12)).padStart(2, '0')}-${String(3 + i).padStart(2, '0')}`,
})),
rowKey: 'id',
columnToolbar: true,
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
toolbar = { position: 'top', showLabels: true };
log({
ko: '칩을 눌러 컬럼을 숨기거나 보이고, 칩을 끌어 순서를 바꿔 보세요.',
en: 'Press a chip to hide or show its column, and drag a chip to reorder.',
});
const offs = [
api.on('columnVisibilityChanged', ({ columnId, hidden }) =>
log({
ko: `${columnId} 컬럼을 ${hidden ? '숨겼어요' : '보여요'}`,
en: `Column ${columnId} ${hidden ? 'hidden' : 'shown'}`,
}),
),
api.on('columnMoved', ({ columnId, order }) =>
log({
ko: `${columnId} 이동 → ${order.join(' · ')}`,
en: `${columnId} moved → ${order.join(' · ')}`,
}),
),
];
return () => offs.forEach((off) => off());
}
export const actions = {
position: (api: GridApi<Row>, value?: string) => {
toolbar = { ...toolbar, position: value === 'bottom' ? 'bottom' : 'top' };
api.setOptions({ columnToolbar: toolbar });
},
labels: (api: GridApi<Row>, value?: string) => {
toolbar = { ...toolbar, showLabels: value !== 'icons' };
api.setOptions({ columnToolbar: toolbar });
},
showAll: (api: GridApi<Row>) => api.showAllColumns(),
};버튼을 누르면 이 예제의 코드가 StackBlitz나 CodeSandbox로 전송돼요. 누르기 전에는 아무것도 보내지 않아요.
<script setup lang="ts">
import { onBeforeUnmount, shallowRef } from 'vue';
import { Grid, type GridApi } from '@maxgrid/vue';
import { actions, options, setup, type Row } from './example';
const api = shallowRef<GridApi<Row> | null>(null);
let stop: (() => void) | undefined;
function onReady(event: { api: GridApi<Row> }) {
api.value = event.api;
stop = setup(event.api, console.log);
}
onBeforeUnmount(() => stop?.());
</script>
<template>
<div class="toolbar">
<select
aria-label="칩 위치"
:disabled="!api"
@change="api && actions.position(api, ($event.target as HTMLSelectElement).value)"
>
<option value="top" selected>위</option>
<option value="bottom">아래</option>
</select>
<select
aria-label="칩 글자"
:disabled="!api"
@change="api && actions.labels(api, ($event.target as HTMLSelectElement).value)"
>
<option value="labels" selected>컬럼 제목 보이기</option>
<option value="icons">아이콘만</option>
</select>
<button type="button" :disabled="!api" @click="api && actions.showAll(api)">숨긴 컬럼 모두 보이기</button>
</div>
<Grid style="height: 330px" :options="options" @ready="onReady" />
</template>import type { GridApi, GridOptions } from '@maxgrid/vue';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
name: string;
team: string;
city: string;
email: string;
joined: string;
}
const names = ['김서연', '이준호', '박민지', '최도윤', '정하은', '강지후', '윤서아', '임태민'];
const teams = ['개발', '디자인', '영업', '인사'];
const cities = ['서울', '부산', '대구', '인천', '광주'];
// columnToolbar: true면 그리드 위에 컬럼마다 칩이 하나 생겨요. 칩을 누르면 컬럼이 보이거나 숨고,
// 칩을 끌거나 Alt+←/→를 누르면 컬럼 순서가 바뀌어요. 칩 모양은 { position, showLabels }로 정해요.
let toolbar: { position: 'top' | 'bottom'; showLabels: boolean } = {
position: 'top',
showLabels: true,
};
export const options: GridOptions<Row> = {
columns: [
{ id: 'id', title: '번호', width: 70, align: 'end' },
{ id: 'name', title: '이름', width: 120 },
{ id: 'team', title: '팀', width: 100 },
{ id: 'city', title: '지역', width: 100 },
{ id: 'email', title: '이메일', width: 200 },
{ id: 'joined', title: '입사일', width: 120 },
],
rows: Array.from({ length: 12 }, (_, i) => ({
id: i + 1,
name: names[i % names.length],
team: teams[(i * 3) % teams.length],
city: cities[(i * 2) % cities.length],
email: `user${i + 1}@example.com`,
joined: `2023-${String(1 + (i % 12)).padStart(2, '0')}-${String(3 + i).padStart(2, '0')}`,
})),
rowKey: 'id',
columnToolbar: true,
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
toolbar = { position: 'top', showLabels: true };
log({
ko: '칩을 눌러 컬럼을 숨기거나 보이고, 칩을 끌어 순서를 바꿔 보세요.',
en: 'Press a chip to hide or show its column, and drag a chip to reorder.',
});
const offs = [
api.on('columnVisibilityChanged', ({ columnId, hidden }) =>
log({
ko: `${columnId} 컬럼을 ${hidden ? '숨겼어요' : '보여요'}`,
en: `Column ${columnId} ${hidden ? 'hidden' : 'shown'}`,
}),
),
api.on('columnMoved', ({ columnId, order }) =>
log({
ko: `${columnId} 이동 → ${order.join(' · ')}`,
en: `${columnId} moved → ${order.join(' · ')}`,
}),
),
];
return () => offs.forEach((off) => off());
}
export const actions = {
position: (api: GridApi<Row>, value?: string) => {
toolbar = { ...toolbar, position: value === 'bottom' ? 'bottom' : 'top' };
api.setOptions({ columnToolbar: toolbar });
},
labels: (api: GridApi<Row>, value?: string) => {
toolbar = { ...toolbar, showLabels: value !== 'icons' };
api.setOptions({ columnToolbar: toolbar });
},
showAll: (api: GridApi<Row>) => api.showAllColumns(),
};버튼을 누르면 이 예제의 코드가 StackBlitz나 CodeSandbox로 전송돼요. 누르기 전에는 아무것도 보내지 않아요.
import { Component, OnDestroy } from '@angular/core';
import { GridComponent, isGridEvent, type GridApi, type GridEventMessage } from '@maxgrid/angular';
import { actions, options, setup, type Row } from './example';
@Component({
selector: 'app-example-grid',
standalone: true,
imports: [GridComponent],
template: `
<div class="toolbar">
<select
aria-label="칩 위치"
[disabled]="!api"
(change)="api && actions.position(api, $any($event.target).value)"
>
<option value="top" selected>위</option>
<option value="bottom">아래</option>
</select>
<select
aria-label="칩 글자"
[disabled]="!api"
(change)="api && actions.labels(api, $any($event.target).value)"
>
<option value="labels" selected>컬럼 제목 보이기</option>
<option value="icons">아이콘만</option>
</select>
<button
type="button"
[disabled]="!api"
(click)="api && actions.showAll(api)"
>숨긴 컬럼 모두 보이기</button>
</div>
<mx-grid style="height: 330px" [options]="options" [events]="relayed" (gridEvent)="onEvent($event)" />
`,
})
export class ExampleGridComponent implements OnDestroy {
readonly options = options;
readonly actions = actions;
readonly relayed = ['ready'] as const;
api: GridApi<Row> | null = null;
private stop: (() => void) | null = null;
onEvent(event: GridEventMessage<Row>): void {
if (isGridEvent(event, 'ready')) {
this.api = event.payload.api;
this.stop = setup(this.api, console.log);
}
}
ngOnDestroy(): void {
this.stop?.();
}
}import type { GridApi, GridOptions } from '@maxgrid/angular';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
name: string;
team: string;
city: string;
email: string;
joined: string;
}
const names = ['김서연', '이준호', '박민지', '최도윤', '정하은', '강지후', '윤서아', '임태민'];
const teams = ['개발', '디자인', '영업', '인사'];
const cities = ['서울', '부산', '대구', '인천', '광주'];
// columnToolbar: true면 그리드 위에 컬럼마다 칩이 하나 생겨요. 칩을 누르면 컬럼이 보이거나 숨고,
// 칩을 끌거나 Alt+←/→를 누르면 컬럼 순서가 바뀌어요. 칩 모양은 { position, showLabels }로 정해요.
let toolbar: { position: 'top' | 'bottom'; showLabels: boolean } = {
position: 'top',
showLabels: true,
};
export const options: GridOptions<Row> = {
columns: [
{ id: 'id', title: '번호', width: 70, align: 'end' },
{ id: 'name', title: '이름', width: 120 },
{ id: 'team', title: '팀', width: 100 },
{ id: 'city', title: '지역', width: 100 },
{ id: 'email', title: '이메일', width: 200 },
{ id: 'joined', title: '입사일', width: 120 },
],
rows: Array.from({ length: 12 }, (_, i) => ({
id: i + 1,
name: names[i % names.length],
team: teams[(i * 3) % teams.length],
city: cities[(i * 2) % cities.length],
email: `user${i + 1}@example.com`,
joined: `2023-${String(1 + (i % 12)).padStart(2, '0')}-${String(3 + i).padStart(2, '0')}`,
})),
rowKey: 'id',
columnToolbar: true,
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
toolbar = { position: 'top', showLabels: true };
log({
ko: '칩을 눌러 컬럼을 숨기거나 보이고, 칩을 끌어 순서를 바꿔 보세요.',
en: 'Press a chip to hide or show its column, and drag a chip to reorder.',
});
const offs = [
api.on('columnVisibilityChanged', ({ columnId, hidden }) =>
log({
ko: `${columnId} 컬럼을 ${hidden ? '숨겼어요' : '보여요'}`,
en: `Column ${columnId} ${hidden ? 'hidden' : 'shown'}`,
}),
),
api.on('columnMoved', ({ columnId, order }) =>
log({
ko: `${columnId} 이동 → ${order.join(' · ')}`,
en: `${columnId} moved → ${order.join(' · ')}`,
}),
),
];
return () => offs.forEach((off) => off());
}
export const actions = {
position: (api: GridApi<Row>, value?: string) => {
toolbar = { ...toolbar, position: value === 'bottom' ? 'bottom' : 'top' };
api.setOptions({ columnToolbar: toolbar });
},
labels: (api: GridApi<Row>, value?: string) => {
toolbar = { ...toolbar, showLabels: value !== 'icons' };
api.setOptions({ columnToolbar: toolbar });
},
showAll: (api: GridApi<Row>) => api.showAllColumns(),
};When you click, the example code is sent to StackBlitz or CodeSandbox. Nothing is sent before you click.
<div id="app">
<div class="toolbar">
<select aria-label="Chip position" id="position">
<option value="top" selected>Top</option>
<option value="bottom">Bottom</option>
</select>
<select aria-label="Chip text" id="labels">
<option value="labels" selected>Show titles</option>
<option value="icons">Icons only</option>
</select>
<button type="button" id="showAll">Show all columns</button>
</div>
<div id="grid" style="height: 330px"></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('position').addEventListener('change', (event) => actions.position(api, event.target.value));
document.getElementById('labels').addEventListener('change', (event) => actions.labels(api, event.target.value));
document.getElementById('showAll').addEventListener('click', () => actions.showAll(api));const names = [
'Liam Carter',
'Emma Stone',
'Noah Hayes',
'Olivia Reed',
'Ethan Brooks',
'Ava Foster',
'Mason Clark',
'Mia Turner',
];
const teams = ['Dev', 'Design', 'Sales', 'HR'];
const cities = ['Austin', 'Boston', 'Denver', 'Seattle', 'Portland'];
// With columnToolbar: true a strip above the grid shows one chip per column. Press a chip to hide or show its column,
// and drag a chip or press Alt+Left/Right to reorder. The strip itself is set with { position, showLabels }.
let toolbar = {
position: 'top',
showLabels: true,
};
export const options = {
columns: [
{ id: 'id', title: 'No.', width: 70, align: 'end' },
{ id: 'name', title: 'Name', width: 130 },
{ id: 'team', title: 'Team', width: 100 },
{ id: 'city', title: 'City', width: 100 },
{ id: 'email', title: 'Email', width: 200 },
{ id: 'joined', title: 'Joined', width: 120 },
],
rows: Array.from({ length: 12 }, (_, i) => ({
id: i + 1,
name: names[i % names.length],
team: teams[(i * 3) % teams.length],
city: cities[(i * 2) % cities.length],
email: `user${i + 1}@example.com`,
joined: `2023-${String(1 + (i % 12)).padStart(2, '0')}-${String(3 + i).padStart(2, '0')}`,
})),
rowKey: 'id',
columnToolbar: true,
};
export function setup(api, log) {
toolbar = { position: 'top', showLabels: true };
log('Press a chip to hide or show its column, and drag a chip to reorder.');
const offs = [
api.on('columnVisibilityChanged', ({ columnId, hidden }) => log(`Column ${columnId} ${hidden ? 'hidden' : 'shown'}`)),
api.on('columnMoved', ({ columnId, order }) => log(`${columnId} moved → ${order.join(' · ')}`)),
];
return () => offs.forEach((off) => off());
}
export const actions = {
position: (api, value) => {
toolbar = { ...toolbar, position: value === 'bottom' ? 'bottom' : 'top' };
api.setOptions({ columnToolbar: toolbar });
},
labels: (api, value) => {
toolbar = { ...toolbar, showLabels: value !== 'icons' };
api.setOptions({ columnToolbar: toolbar });
},
showAll: (api) => api.showAllColumns(),
};<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Hide and reorder columns with the column toolbar</title>
</head>
<body>
<div class="toolbar">
<select aria-label="Chip position" id="position">
<option value="top" selected>Top</option>
<option value="bottom">Bottom</option>
</select>
<select aria-label="Chip text" id="labels">
<option value="labels" selected>Show titles</option>
<option value="icons">Icons only</option>
</select>
<button type="button" id="showAll">Show all columns</button>
</div>
<div id="grid" style="height: 330px"></div>
<ul id="log" aria-live="polite"></ul>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script>
const names = [
'Liam Carter',
'Emma Stone',
'Noah Hayes',
'Olivia Reed',
'Ethan Brooks',
'Ava Foster',
'Mason Clark',
'Mia Turner',
];
const teams = ['Dev', 'Design', 'Sales', 'HR'];
const cities = ['Austin', 'Boston', 'Denver', 'Seattle', 'Portland'];
// With columnToolbar: true a strip above the grid shows one chip per column. Press a chip to hide or show its column,
// and drag a chip or press Alt+Left/Right to reorder. The strip itself is set with { position, showLabels }.
let toolbar = {
position: 'top',
showLabels: true,
};
const options = {
columns: [
{ id: 'id', title: 'No.', width: 70, align: 'end' },
{ id: 'name', title: 'Name', width: 130 },
{ id: 'team', title: 'Team', width: 100 },
{ id: 'city', title: 'City', width: 100 },
{ id: 'email', title: 'Email', width: 200 },
{ id: 'joined', title: 'Joined', width: 120 },
],
rows: Array.from({ length: 12 }, (_, i) => ({
id: i + 1,
name: names[i % names.length],
team: teams[(i * 3) % teams.length],
city: cities[(i * 2) % cities.length],
email: `user${i + 1}@example.com`,
joined: `2023-${String(1 + (i % 12)).padStart(2, '0')}-${String(3 + i).padStart(2, '0')}`,
})),
rowKey: 'id',
columnToolbar: true,
};
function setup(api, log) {
toolbar = { position: 'top', showLabels: true };
log('Press a chip to hide or show its column, and drag a chip to reorder.');
const offs = [
api.on('columnVisibilityChanged', ({ columnId, hidden }) => log(`Column ${columnId} ${hidden ? 'hidden' : 'shown'}`)),
api.on('columnMoved', ({ columnId, order }) => log(`${columnId} moved → ${order.join(' · ')}`)),
];
return () => offs.forEach((off) => off());
}
const actions = {
position: (api, value) => {
toolbar = { ...toolbar, position: value === 'bottom' ? 'bottom' : 'top' };
api.setOptions({ columnToolbar: toolbar });
},
labels: (api, value) => {
toolbar = { ...toolbar, showLabels: value !== 'icons' };
api.setOptions({ columnToolbar: toolbar });
},
showAll: (api) => api.showAllColumns(),
};
options.ariaLabel = "Hide and reorder columns with the column toolbar";
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('position').addEventListener('change', (event) => actions.position(api, event.target.value));
document.getElementById('labels').addEventListener('change', (event) => actions.labels(api, event.target.value));
document.getElementById('showAll').addEventListener('click', () => actions.showAll(api));
</script>
</body>
</html>When you click, the example code is sent to StackBlitz or CodeSandbox. Nothing is sent before you click.
import { useEffect } from 'react';
import { Grid, useGridApi } from '@maxgrid/react';
import { actions, options, setup, type Row } from './example';
export function ExampleGrid() {
const [api, gridRef] = useGridApi<Row>();
useEffect(() => (api ? setup(api, console.log) : undefined), [api]);
return (
<>
<div className="toolbar">
<select
aria-label="Chip position"
disabled={!api}
onChange={(event) => api && actions.position(api, event.target.value)}
>
<option value="top">Top</option>
<option value="bottom">Bottom</option>
</select>
<select defaultValue="top"
aria-label="Chip text"
disabled={!api}
onChange={(event) => api && actions.labels(api, event.target.value)}
>
<option value="labels">Show titles</option>
<option value="icons">Icons only</option>
</select>
<button
type="button"
disabled={!api}
onClick={() => api && actions.showAll(api)}
>Show all columns</button>
</div>
<Grid style={{ height: 330 }} ref={gridRef} options={options} />
</>
);
}import type { GridApi, GridOptions } from '@maxgrid/react';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
name: string;
team: string;
city: string;
email: string;
joined: string;
}
const names = [
'Liam Carter',
'Emma Stone',
'Noah Hayes',
'Olivia Reed',
'Ethan Brooks',
'Ava Foster',
'Mason Clark',
'Mia Turner',
];
const teams = ['Dev', 'Design', 'Sales', 'HR'];
const cities = ['Austin', 'Boston', 'Denver', 'Seattle', 'Portland'];
// With columnToolbar: true a strip above the grid shows one chip per column. Press a chip to hide or show its column,
// and drag a chip or press Alt+Left/Right to reorder. The strip itself is set with { position, showLabels }.
let toolbar: { position: 'top' | 'bottom'; showLabels: boolean } = {
position: 'top',
showLabels: true,
};
export const options: GridOptions<Row> = {
columns: [
{ id: 'id', title: 'No.', width: 70, align: 'end' },
{ id: 'name', title: 'Name', width: 130 },
{ id: 'team', title: 'Team', width: 100 },
{ id: 'city', title: 'City', width: 100 },
{ id: 'email', title: 'Email', width: 200 },
{ id: 'joined', title: 'Joined', width: 120 },
],
rows: Array.from({ length: 12 }, (_, i) => ({
id: i + 1,
name: names[i % names.length],
team: teams[(i * 3) % teams.length],
city: cities[(i * 2) % cities.length],
email: `user${i + 1}@example.com`,
joined: `2023-${String(1 + (i % 12)).padStart(2, '0')}-${String(3 + i).padStart(2, '0')}`,
})),
rowKey: 'id',
columnToolbar: true,
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
toolbar = { position: 'top', showLabels: true };
log('Press a chip to hide or show its column, and drag a chip to reorder.');
const offs = [
api.on('columnVisibilityChanged', ({ columnId, hidden }) =>
log(`Column ${columnId} ${hidden ? 'hidden' : 'shown'}`),
),
api.on('columnMoved', ({ columnId, order }) => log(`${columnId} moved → ${order.join(' · ')}`)),
];
return () => offs.forEach((off) => off());
}
export const actions = {
position: (api: GridApi<Row>, value?: string) => {
toolbar = { ...toolbar, position: value === 'bottom' ? 'bottom' : 'top' };
api.setOptions({ columnToolbar: toolbar });
},
labels: (api: GridApi<Row>, value?: string) => {
toolbar = { ...toolbar, showLabels: value !== 'icons' };
api.setOptions({ columnToolbar: toolbar });
},
showAll: (api: GridApi<Row>) => api.showAllColumns(),
};When you click, the example code is sent to StackBlitz or CodeSandbox. Nothing is sent before you click.
<script setup lang="ts">
import { onBeforeUnmount, shallowRef } from 'vue';
import { Grid, type GridApi } from '@maxgrid/vue';
import { actions, options, setup, type Row } from './example';
const api = shallowRef<GridApi<Row> | null>(null);
let stop: (() => void) | undefined;
function onReady(event: { api: GridApi<Row> }) {
api.value = event.api;
stop = setup(event.api, console.log);
}
onBeforeUnmount(() => stop?.());
</script>
<template>
<div class="toolbar">
<select
aria-label="Chip position"
:disabled="!api"
@change="api && actions.position(api, ($event.target as HTMLSelectElement).value)"
>
<option value="top" selected>Top</option>
<option value="bottom">Bottom</option>
</select>
<select
aria-label="Chip text"
:disabled="!api"
@change="api && actions.labels(api, ($event.target as HTMLSelectElement).value)"
>
<option value="labels" selected>Show titles</option>
<option value="icons">Icons only</option>
</select>
<button type="button" :disabled="!api" @click="api && actions.showAll(api)">Show all columns</button>
</div>
<Grid style="height: 330px" :options="options" @ready="onReady" />
</template>import type { GridApi, GridOptions } from '@maxgrid/vue';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
name: string;
team: string;
city: string;
email: string;
joined: string;
}
const names = [
'Liam Carter',
'Emma Stone',
'Noah Hayes',
'Olivia Reed',
'Ethan Brooks',
'Ava Foster',
'Mason Clark',
'Mia Turner',
];
const teams = ['Dev', 'Design', 'Sales', 'HR'];
const cities = ['Austin', 'Boston', 'Denver', 'Seattle', 'Portland'];
// With columnToolbar: true a strip above the grid shows one chip per column. Press a chip to hide or show its column,
// and drag a chip or press Alt+Left/Right to reorder. The strip itself is set with { position, showLabels }.
let toolbar: { position: 'top' | 'bottom'; showLabels: boolean } = {
position: 'top',
showLabels: true,
};
export const options: GridOptions<Row> = {
columns: [
{ id: 'id', title: 'No.', width: 70, align: 'end' },
{ id: 'name', title: 'Name', width: 130 },
{ id: 'team', title: 'Team', width: 100 },
{ id: 'city', title: 'City', width: 100 },
{ id: 'email', title: 'Email', width: 200 },
{ id: 'joined', title: 'Joined', width: 120 },
],
rows: Array.from({ length: 12 }, (_, i) => ({
id: i + 1,
name: names[i % names.length],
team: teams[(i * 3) % teams.length],
city: cities[(i * 2) % cities.length],
email: `user${i + 1}@example.com`,
joined: `2023-${String(1 + (i % 12)).padStart(2, '0')}-${String(3 + i).padStart(2, '0')}`,
})),
rowKey: 'id',
columnToolbar: true,
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
toolbar = { position: 'top', showLabels: true };
log('Press a chip to hide or show its column, and drag a chip to reorder.');
const offs = [
api.on('columnVisibilityChanged', ({ columnId, hidden }) =>
log(`Column ${columnId} ${hidden ? 'hidden' : 'shown'}`),
),
api.on('columnMoved', ({ columnId, order }) => log(`${columnId} moved → ${order.join(' · ')}`)),
];
return () => offs.forEach((off) => off());
}
export const actions = {
position: (api: GridApi<Row>, value?: string) => {
toolbar = { ...toolbar, position: value === 'bottom' ? 'bottom' : 'top' };
api.setOptions({ columnToolbar: toolbar });
},
labels: (api: GridApi<Row>, value?: string) => {
toolbar = { ...toolbar, showLabels: value !== 'icons' };
api.setOptions({ columnToolbar: toolbar });
},
showAll: (api: GridApi<Row>) => api.showAllColumns(),
};When you click, the example code is sent to StackBlitz or CodeSandbox. Nothing is sent before you click.
import { Component, OnDestroy } from '@angular/core';
import { GridComponent, isGridEvent, type GridApi, type GridEventMessage } from '@maxgrid/angular';
import { actions, options, setup, type Row } from './example';
@Component({
selector: 'app-example-grid',
standalone: true,
imports: [GridComponent],
template: `
<div class="toolbar">
<select
aria-label="Chip position"
[disabled]="!api"
(change)="api && actions.position(api, $any($event.target).value)"
>
<option value="top" selected>Top</option>
<option value="bottom">Bottom</option>
</select>
<select
aria-label="Chip text"
[disabled]="!api"
(change)="api && actions.labels(api, $any($event.target).value)"
>
<option value="labels" selected>Show titles</option>
<option value="icons">Icons only</option>
</select>
<button
type="button"
[disabled]="!api"
(click)="api && actions.showAll(api)"
>Show all columns</button>
</div>
<mx-grid style="height: 330px" [options]="options" [events]="relayed" (gridEvent)="onEvent($event)" />
`,
})
export class ExampleGridComponent implements OnDestroy {
readonly options = options;
readonly actions = actions;
readonly relayed = ['ready'] as const;
api: GridApi<Row> | null = null;
private stop: (() => void) | null = null;
onEvent(event: GridEventMessage<Row>): void {
if (isGridEvent(event, 'ready')) {
this.api = event.payload.api;
this.stop = setup(this.api, console.log);
}
}
ngOnDestroy(): void {
this.stop?.();
}
}import type { GridApi, GridOptions } from '@maxgrid/angular';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
name: string;
team: string;
city: string;
email: string;
joined: string;
}
const names = [
'Liam Carter',
'Emma Stone',
'Noah Hayes',
'Olivia Reed',
'Ethan Brooks',
'Ava Foster',
'Mason Clark',
'Mia Turner',
];
const teams = ['Dev', 'Design', 'Sales', 'HR'];
const cities = ['Austin', 'Boston', 'Denver', 'Seattle', 'Portland'];
// With columnToolbar: true a strip above the grid shows one chip per column. Press a chip to hide or show its column,
// and drag a chip or press Alt+Left/Right to reorder. The strip itself is set with { position, showLabels }.
let toolbar: { position: 'top' | 'bottom'; showLabels: boolean } = {
position: 'top',
showLabels: true,
};
export const options: GridOptions<Row> = {
columns: [
{ id: 'id', title: 'No.', width: 70, align: 'end' },
{ id: 'name', title: 'Name', width: 130 },
{ id: 'team', title: 'Team', width: 100 },
{ id: 'city', title: 'City', width: 100 },
{ id: 'email', title: 'Email', width: 200 },
{ id: 'joined', title: 'Joined', width: 120 },
],
rows: Array.from({ length: 12 }, (_, i) => ({
id: i + 1,
name: names[i % names.length],
team: teams[(i * 3) % teams.length],
city: cities[(i * 2) % cities.length],
email: `user${i + 1}@example.com`,
joined: `2023-${String(1 + (i % 12)).padStart(2, '0')}-${String(3 + i).padStart(2, '0')}`,
})),
rowKey: 'id',
columnToolbar: true,
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
toolbar = { position: 'top', showLabels: true };
log('Press a chip to hide or show its column, and drag a chip to reorder.');
const offs = [
api.on('columnVisibilityChanged', ({ columnId, hidden }) =>
log(`Column ${columnId} ${hidden ? 'hidden' : 'shown'}`),
),
api.on('columnMoved', ({ columnId, order }) => log(`${columnId} moved → ${order.join(' · ')}`)),
];
return () => offs.forEach((off) => off());
}
export const actions = {
position: (api: GridApi<Row>, value?: string) => {
toolbar = { ...toolbar, position: value === 'bottom' ? 'bottom' : 'top' };
api.setOptions({ columnToolbar: toolbar });
},
labels: (api: GridApi<Row>, value?: string) => {
toolbar = { ...toolbar, showLabels: value !== 'icons' };
api.setOptions({ columnToolbar: toolbar });
},
showAll: (api: GridApi<Row>) => api.showAllColumns(),
};