필요한 컬럼만 골라서 보기Show only the columns you need
컬럼을 숨기거나 다시 보이게 해요. 처음부터 숨겨 둔 채 시작할 수도 있고, 헤더 메뉴에서 사용자가 직접 숨길 수도 있어요. 숨겨도 폭과 정렬은 그대로 기억해요.Hide or show columns, start with some hidden, or let users hide them from the header menu. A hidden column keeps its width and sort.
코드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="view">
<option value="initial" selected>처음 상태 (입사일만 숨김)</option>
<option value="all">전부 보기</option>
<option value="summary">요약만 (사번·이름·팀)</option>
<option value="contact">연락용 (이름·연락처·근무지)</option>
<option value="hide-name">이름만 숨기기</option>
<option value="hide-team">팀만 숨기기</option>
<option value="hide-city">근무지만 숨기기</option>
<option value="hide-phone">연락처만 숨기기</option>
<option value="hide-salary">연봉만 숨기기</option>
</select>
</div>
<div id="grid" style="height: 480px"></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('view').addEventListener('change', (event) => actions.view(api, event.target.value));const names = ['김민준', '이서연', '박지호', '최유나', '정도윤', '한소희', '오세훈', '윤지아'];
const teams = ['개발팀', '디자인팀', '영업팀', '인사팀'];
const cities = ['서울', '부산', '대구', '광주', '제주'];
// '입사일'은 처음부터 숨긴 채로 시작해요. 사번은 아래 버튼으로는 숨기지 못하게 막아 두었어요(늘 보여야 하는 컬럼 예시).
// 컬럼 정의에 hidden: true만 쓰면 돼요. 숨긴 컬럼도 정렬·폭·필터 상태는 그대로 기억해요.
export const options = {
columns: [
{ id: 'id', title: '사번', width: 80, align: 'end' },
{ id: 'name', title: '이름', width: 110 },
{ id: 'team', title: '팀', width: 110 },
{ id: 'city', title: '근무지', width: 100 },
{ id: 'phone', title: '연락처', width: 140 },
{ id: 'salary', title: '연봉(만원)', kind: 'number', width: 120, align: 'end' },
{ id: 'joined', title: '입사일', width: 120, hidden: true },
],
headerGroups: [
{ id: 'person', title: '인적 사항', children: ['name', 'team', 'city'] },
{ id: 'etc', title: '그 밖의 정보', children: ['phone', 'salary', 'joined'] },
],
rows: Array.from({ length: 12 }, (_, i) => ({
id: 1001 + i,
name: names[i % 8],
team: teams[(i * 3) % 4],
city: cities[(i * 2) % 5],
phone: `010-${String(2000 + i * 391).slice(0, 4)}-${String(5100 + i * 733).slice(0, 4)}`,
salary: 4200 + ((i * 370) % 2400),
joined: `20${18 + (i % 6)}-${String(1 + ((i * 5) % 12)).padStart(2, '0')}-${String(3 + ((i * 7) % 25)).padStart(2, '0')}`,
})),
rowKey: 'id',
// 헤더 오른쪽 메뉴(⋮)에서도 숨길 수 있어요. 사용자가 직접 숨기는 가장 쉬운 길이에요.
columnMenu: true,
};
export function setup(api, log) {
const off = api.on('columnVisibilityChanged', ({ columnId, hidden }) => {
const title = api.getColumns().find((c) => c.id === columnId)?.title ?? columnId;
const shown = api.getColumnState().filter((s) => !s.hidden).length;
log({
ko: `${title} ${hidden ? '숨김' : '표시'} · 지금 보이는 컬럼 ${shown}개`,
en: `${title} ${hidden ? 'hidden' : 'shown'} · ${shown} columns visible now`,
});
});
return () => off();
}
// 보기 방식 한 번에 바꾸기: 보일 컬럼 목록만 정해 주면 나머지는 숨겨요. 사번은 어느 방식에서도 늘 보여요.
const VIEWS = {
initial: ['id', 'name', 'team', 'city', 'phone', 'salary'],
all: ['id', 'name', 'team', 'city', 'phone', 'salary', 'joined'],
summary: ['id', 'name', 'team'],
contact: ['id', 'name', 'phone', 'city'],
'hide-name': ['id', 'team', 'city', 'phone', 'salary', 'joined'],
'hide-team': ['id', 'name', 'city', 'phone', 'salary', 'joined'],
'hide-city': ['id', 'name', 'team', 'phone', 'salary', 'joined'],
'hide-phone': ['id', 'name', 'team', 'city', 'salary', 'joined'],
'hide-salary': ['id', 'name', 'team', 'city', 'phone', 'joined'],
};
export const actions = {
view: (api, value) => {
const show = new Set(VIEWS[value ?? 'initial'] ?? VIEWS.initial);
api.getColumns().forEach((c) => api.setColumnVisible(c.id, show.has(c.id)));
},
};<!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="view">
<option value="initial" selected>처음 상태 (입사일만 숨김)</option>
<option value="all">전부 보기</option>
<option value="summary">요약만 (사번·이름·팀)</option>
<option value="contact">연락용 (이름·연락처·근무지)</option>
<option value="hide-name">이름만 숨기기</option>
<option value="hide-team">팀만 숨기기</option>
<option value="hide-city">근무지만 숨기기</option>
<option value="hide-phone">연락처만 숨기기</option>
<option value="hide-salary">연봉만 숨기기</option>
</select>
</div>
<div id="grid" style="height: 480px"></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 = ['서울', '부산', '대구', '광주', '제주'];
// '입사일'은 처음부터 숨긴 채로 시작해요. 사번은 아래 버튼으로는 숨기지 못하게 막아 두었어요(늘 보여야 하는 컬럼 예시).
// 컬럼 정의에 hidden: true만 쓰면 돼요. 숨긴 컬럼도 정렬·폭·필터 상태는 그대로 기억해요.
const options = {
columns: [
{ id: 'id', title: '사번', width: 80, align: 'end' },
{ id: 'name', title: '이름', width: 110 },
{ id: 'team', title: '팀', width: 110 },
{ id: 'city', title: '근무지', width: 100 },
{ id: 'phone', title: '연락처', width: 140 },
{ id: 'salary', title: '연봉(만원)', kind: 'number', width: 120, align: 'end' },
{ id: 'joined', title: '입사일', width: 120, hidden: true },
],
headerGroups: [
{ id: 'person', title: '인적 사항', children: ['name', 'team', 'city'] },
{ id: 'etc', title: '그 밖의 정보', children: ['phone', 'salary', 'joined'] },
],
rows: Array.from({ length: 12 }, (_, i) => ({
id: 1001 + i,
name: names[i % 8],
team: teams[(i * 3) % 4],
city: cities[(i * 2) % 5],
phone: `010-${String(2000 + i * 391).slice(0, 4)}-${String(5100 + i * 733).slice(0, 4)}`,
salary: 4200 + ((i * 370) % 2400),
joined: `20${18 + (i % 6)}-${String(1 + ((i * 5) % 12)).padStart(2, '0')}-${String(3 + ((i * 7) % 25)).padStart(2, '0')}`,
})),
rowKey: 'id',
// 헤더 오른쪽 메뉴(⋮)에서도 숨길 수 있어요. 사용자가 직접 숨기는 가장 쉬운 길이에요.
columnMenu: true,
};
function setup(api, log) {
const off = api.on('columnVisibilityChanged', ({ columnId, hidden }) => {
const title = api.getColumns().find((c) => c.id === columnId)?.title ?? columnId;
const shown = api.getColumnState().filter((s) => !s.hidden).length;
log({
ko: `${title} ${hidden ? '숨김' : '표시'} · 지금 보이는 컬럼 ${shown}개`,
en: `${title} ${hidden ? 'hidden' : 'shown'} · ${shown} columns visible now`,
});
});
return () => off();
}
// 보기 방식 한 번에 바꾸기: 보일 컬럼 목록만 정해 주면 나머지는 숨겨요. 사번은 어느 방식에서도 늘 보여요.
const VIEWS = {
initial: ['id', 'name', 'team', 'city', 'phone', 'salary'],
all: ['id', 'name', 'team', 'city', 'phone', 'salary', 'joined'],
summary: ['id', 'name', 'team'],
contact: ['id', 'name', 'phone', 'city'],
'hide-name': ['id', 'team', 'city', 'phone', 'salary', 'joined'],
'hide-team': ['id', 'name', 'city', 'phone', 'salary', 'joined'],
'hide-city': ['id', 'name', 'team', 'phone', 'salary', 'joined'],
'hide-phone': ['id', 'name', 'team', 'city', 'salary', 'joined'],
'hide-salary': ['id', 'name', 'team', 'city', 'phone', 'joined'],
};
const actions = {
view: (api, value) => {
const show = new Set(VIEWS[value ?? 'initial'] ?? VIEWS.initial);
api.getColumns().forEach((c) => api.setColumnVisible(c.id, show.has(c.id)));
},
};
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('view').addEventListener('change', (event) => actions.view(api, event.target.value));
</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.view(api, event.target.value)}
>
<option value="initial">처음 상태 (입사일만 숨김)</option>
<option value="all">전부 보기</option>
<option value="summary">요약만 (사번·이름·팀)</option>
<option value="contact">연락용 (이름·연락처·근무지)</option>
<option value="hide-name">이름만 숨기기</option>
<option value="hide-team">팀만 숨기기</option>
<option value="hide-city">근무지만 숨기기</option>
<option value="hide-phone">연락처만 숨기기</option>
<option value="hide-salary">연봉만 숨기기</option>
</select>
</div>
<Grid style={{ height: 480 }} 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;
phone: string;
salary: number;
joined: string;
}
const names = ['김민준', '이서연', '박지호', '최유나', '정도윤', '한소희', '오세훈', '윤지아'];
const teams = ['개발팀', '디자인팀', '영업팀', '인사팀'];
const cities = ['서울', '부산', '대구', '광주', '제주'];
// '입사일'은 처음부터 숨긴 채로 시작해요. 사번은 아래 버튼으로는 숨기지 못하게 막아 두었어요(늘 보여야 하는 컬럼 예시).
// 컬럼 정의에 hidden: true만 쓰면 돼요. 숨긴 컬럼도 정렬·폭·필터 상태는 그대로 기억해요.
export const options: GridOptions<Row> = {
columns: [
{ id: 'id', title: '사번', width: 80, align: 'end' },
{ id: 'name', title: '이름', width: 110 },
{ id: 'team', title: '팀', width: 110 },
{ id: 'city', title: '근무지', width: 100 },
{ id: 'phone', title: '연락처', width: 140 },
{ id: 'salary', title: '연봉(만원)', kind: 'number', width: 120, align: 'end' },
{ id: 'joined', title: '입사일', width: 120, hidden: true },
],
headerGroups: [
{ id: 'person', title: '인적 사항', children: ['name', 'team', 'city'] },
{ id: 'etc', title: '그 밖의 정보', children: ['phone', 'salary', 'joined'] },
],
rows: Array.from({ length: 12 }, (_, i) => ({
id: 1001 + i,
name: names[i % 8] as string,
team: teams[(i * 3) % 4] as string,
city: cities[(i * 2) % 5] as string,
phone: `010-${String(2000 + i * 391).slice(0, 4)}-${String(5100 + i * 733).slice(0, 4)}`,
salary: 4200 + ((i * 370) % 2400),
joined: `20${18 + (i % 6)}-${String(1 + ((i * 5) % 12)).padStart(2, '0')}-${String(3 + ((i * 7) % 25)).padStart(2, '0')}`,
})),
rowKey: 'id',
// 헤더 오른쪽 메뉴(⋮)에서도 숨길 수 있어요. 사용자가 직접 숨기는 가장 쉬운 길이에요.
columnMenu: true,
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
const off = api.on('columnVisibilityChanged', ({ columnId, hidden }) => {
const title = api.getColumns().find((c) => c.id === columnId)?.title ?? columnId;
const shown = api.getColumnState().filter((s) => !s.hidden).length;
log({
ko: `${title} ${hidden ? '숨김' : '표시'} · 지금 보이는 컬럼 ${shown}개`,
en: `${title} ${hidden ? 'hidden' : 'shown'} · ${shown} columns visible now`,
});
});
return () => off();
}
// 보기 방식 한 번에 바꾸기: 보일 컬럼 목록만 정해 주면 나머지는 숨겨요. 사번은 어느 방식에서도 늘 보여요.
const VIEWS: Record<string, string[]> = {
initial: ['id', 'name', 'team', 'city', 'phone', 'salary'],
all: ['id', 'name', 'team', 'city', 'phone', 'salary', 'joined'],
summary: ['id', 'name', 'team'],
contact: ['id', 'name', 'phone', 'city'],
'hide-name': ['id', 'team', 'city', 'phone', 'salary', 'joined'],
'hide-team': ['id', 'name', 'city', 'phone', 'salary', 'joined'],
'hide-city': ['id', 'name', 'team', 'phone', 'salary', 'joined'],
'hide-phone': ['id', 'name', 'team', 'city', 'salary', 'joined'],
'hide-salary': ['id', 'name', 'team', 'city', 'phone', 'joined'],
};
export const actions = {
view: (api: GridApi<Row>, value?: string) => {
const show = new Set(VIEWS[value ?? 'initial'] ?? VIEWS.initial);
api.getColumns().forEach((c) => api.setColumnVisible(c.id, show.has(c.id)));
},
};버튼을 누르면 이 예제의 코드가 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.view(api, ($event.target as HTMLSelectElement).value)"
>
<option value="initial" selected>처음 상태 (입사일만 숨김)</option>
<option value="all">전부 보기</option>
<option value="summary">요약만 (사번·이름·팀)</option>
<option value="contact">연락용 (이름·연락처·근무지)</option>
<option value="hide-name">이름만 숨기기</option>
<option value="hide-team">팀만 숨기기</option>
<option value="hide-city">근무지만 숨기기</option>
<option value="hide-phone">연락처만 숨기기</option>
<option value="hide-salary">연봉만 숨기기</option>
</select>
</div>
<Grid style="height: 480px" :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;
phone: string;
salary: number;
joined: string;
}
const names = ['김민준', '이서연', '박지호', '최유나', '정도윤', '한소희', '오세훈', '윤지아'];
const teams = ['개발팀', '디자인팀', '영업팀', '인사팀'];
const cities = ['서울', '부산', '대구', '광주', '제주'];
// '입사일'은 처음부터 숨긴 채로 시작해요. 사번은 아래 버튼으로는 숨기지 못하게 막아 두었어요(늘 보여야 하는 컬럼 예시).
// 컬럼 정의에 hidden: true만 쓰면 돼요. 숨긴 컬럼도 정렬·폭·필터 상태는 그대로 기억해요.
export const options: GridOptions<Row> = {
columns: [
{ id: 'id', title: '사번', width: 80, align: 'end' },
{ id: 'name', title: '이름', width: 110 },
{ id: 'team', title: '팀', width: 110 },
{ id: 'city', title: '근무지', width: 100 },
{ id: 'phone', title: '연락처', width: 140 },
{ id: 'salary', title: '연봉(만원)', kind: 'number', width: 120, align: 'end' },
{ id: 'joined', title: '입사일', width: 120, hidden: true },
],
headerGroups: [
{ id: 'person', title: '인적 사항', children: ['name', 'team', 'city'] },
{ id: 'etc', title: '그 밖의 정보', children: ['phone', 'salary', 'joined'] },
],
rows: Array.from({ length: 12 }, (_, i) => ({
id: 1001 + i,
name: names[i % 8] as string,
team: teams[(i * 3) % 4] as string,
city: cities[(i * 2) % 5] as string,
phone: `010-${String(2000 + i * 391).slice(0, 4)}-${String(5100 + i * 733).slice(0, 4)}`,
salary: 4200 + ((i * 370) % 2400),
joined: `20${18 + (i % 6)}-${String(1 + ((i * 5) % 12)).padStart(2, '0')}-${String(3 + ((i * 7) % 25)).padStart(2, '0')}`,
})),
rowKey: 'id',
// 헤더 오른쪽 메뉴(⋮)에서도 숨길 수 있어요. 사용자가 직접 숨기는 가장 쉬운 길이에요.
columnMenu: true,
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
const off = api.on('columnVisibilityChanged', ({ columnId, hidden }) => {
const title = api.getColumns().find((c) => c.id === columnId)?.title ?? columnId;
const shown = api.getColumnState().filter((s) => !s.hidden).length;
log({
ko: `${title} ${hidden ? '숨김' : '표시'} · 지금 보이는 컬럼 ${shown}개`,
en: `${title} ${hidden ? 'hidden' : 'shown'} · ${shown} columns visible now`,
});
});
return () => off();
}
// 보기 방식 한 번에 바꾸기: 보일 컬럼 목록만 정해 주면 나머지는 숨겨요. 사번은 어느 방식에서도 늘 보여요.
const VIEWS: Record<string, string[]> = {
initial: ['id', 'name', 'team', 'city', 'phone', 'salary'],
all: ['id', 'name', 'team', 'city', 'phone', 'salary', 'joined'],
summary: ['id', 'name', 'team'],
contact: ['id', 'name', 'phone', 'city'],
'hide-name': ['id', 'team', 'city', 'phone', 'salary', 'joined'],
'hide-team': ['id', 'name', 'city', 'phone', 'salary', 'joined'],
'hide-city': ['id', 'name', 'team', 'phone', 'salary', 'joined'],
'hide-phone': ['id', 'name', 'team', 'city', 'salary', 'joined'],
'hide-salary': ['id', 'name', 'team', 'city', 'phone', 'joined'],
};
export const actions = {
view: (api: GridApi<Row>, value?: string) => {
const show = new Set(VIEWS[value ?? 'initial'] ?? VIEWS.initial);
api.getColumns().forEach((c) => api.setColumnVisible(c.id, show.has(c.id)));
},
};버튼을 누르면 이 예제의 코드가 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.view(api, $any($event.target).value)"
>
<option value="initial" selected>처음 상태 (입사일만 숨김)</option>
<option value="all">전부 보기</option>
<option value="summary">요약만 (사번·이름·팀)</option>
<option value="contact">연락용 (이름·연락처·근무지)</option>
<option value="hide-name">이름만 숨기기</option>
<option value="hide-team">팀만 숨기기</option>
<option value="hide-city">근무지만 숨기기</option>
<option value="hide-phone">연락처만 숨기기</option>
<option value="hide-salary">연봉만 숨기기</option>
</select>
</div>
<mx-grid style="height: 480px" [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;
phone: string;
salary: number;
joined: string;
}
const names = ['김민준', '이서연', '박지호', '최유나', '정도윤', '한소희', '오세훈', '윤지아'];
const teams = ['개발팀', '디자인팀', '영업팀', '인사팀'];
const cities = ['서울', '부산', '대구', '광주', '제주'];
// '입사일'은 처음부터 숨긴 채로 시작해요. 사번은 아래 버튼으로는 숨기지 못하게 막아 두었어요(늘 보여야 하는 컬럼 예시).
// 컬럼 정의에 hidden: true만 쓰면 돼요. 숨긴 컬럼도 정렬·폭·필터 상태는 그대로 기억해요.
export const options: GridOptions<Row> = {
columns: [
{ id: 'id', title: '사번', width: 80, align: 'end' },
{ id: 'name', title: '이름', width: 110 },
{ id: 'team', title: '팀', width: 110 },
{ id: 'city', title: '근무지', width: 100 },
{ id: 'phone', title: '연락처', width: 140 },
{ id: 'salary', title: '연봉(만원)', kind: 'number', width: 120, align: 'end' },
{ id: 'joined', title: '입사일', width: 120, hidden: true },
],
headerGroups: [
{ id: 'person', title: '인적 사항', children: ['name', 'team', 'city'] },
{ id: 'etc', title: '그 밖의 정보', children: ['phone', 'salary', 'joined'] },
],
rows: Array.from({ length: 12 }, (_, i) => ({
id: 1001 + i,
name: names[i % 8] as string,
team: teams[(i * 3) % 4] as string,
city: cities[(i * 2) % 5] as string,
phone: `010-${String(2000 + i * 391).slice(0, 4)}-${String(5100 + i * 733).slice(0, 4)}`,
salary: 4200 + ((i * 370) % 2400),
joined: `20${18 + (i % 6)}-${String(1 + ((i * 5) % 12)).padStart(2, '0')}-${String(3 + ((i * 7) % 25)).padStart(2, '0')}`,
})),
rowKey: 'id',
// 헤더 오른쪽 메뉴(⋮)에서도 숨길 수 있어요. 사용자가 직접 숨기는 가장 쉬운 길이에요.
columnMenu: true,
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
const off = api.on('columnVisibilityChanged', ({ columnId, hidden }) => {
const title = api.getColumns().find((c) => c.id === columnId)?.title ?? columnId;
const shown = api.getColumnState().filter((s) => !s.hidden).length;
log({
ko: `${title} ${hidden ? '숨김' : '표시'} · 지금 보이는 컬럼 ${shown}개`,
en: `${title} ${hidden ? 'hidden' : 'shown'} · ${shown} columns visible now`,
});
});
return () => off();
}
// 보기 방식 한 번에 바꾸기: 보일 컬럼 목록만 정해 주면 나머지는 숨겨요. 사번은 어느 방식에서도 늘 보여요.
const VIEWS: Record<string, string[]> = {
initial: ['id', 'name', 'team', 'city', 'phone', 'salary'],
all: ['id', 'name', 'team', 'city', 'phone', 'salary', 'joined'],
summary: ['id', 'name', 'team'],
contact: ['id', 'name', 'phone', 'city'],
'hide-name': ['id', 'team', 'city', 'phone', 'salary', 'joined'],
'hide-team': ['id', 'name', 'city', 'phone', 'salary', 'joined'],
'hide-city': ['id', 'name', 'team', 'phone', 'salary', 'joined'],
'hide-phone': ['id', 'name', 'team', 'city', 'salary', 'joined'],
'hide-salary': ['id', 'name', 'team', 'city', 'phone', 'joined'],
};
export const actions = {
view: (api: GridApi<Row>, value?: string) => {
const show = new Set(VIEWS[value ?? 'initial'] ?? VIEWS.initial);
api.getColumns().forEach((c) => api.setColumnVisible(c.id, show.has(c.id)));
},
};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="View" id="view">
<option value="initial" selected>Initial (Joined hidden)</option>
<option value="all">Everything</option>
<option value="summary">Summary only</option>
<option value="contact">Contact view</option>
<option value="hide-name">Hide Name</option>
<option value="hide-team">Hide Team</option>
<option value="hide-city">Hide City</option>
<option value="hide-phone">Hide Phone</option>
<option value="hide-salary">Hide Salary</option>
</select>
</div>
<div id="grid" style="height: 480px"></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('view').addEventListener('change', (event) => actions.view(api, event.target.value));const names = [
'Liam Carter',
'Emma Stone',
'Noah Parker',
'Olivia Reed',
'Ethan Brooks',
'Sophia Hayes',
'Mason Wright',
'Ava Morgan',
];
const teams = ['Dev', 'Design', 'Sales', 'HR'];
const cities = ['Seoul', 'Busan', 'Daegu', 'Gwangju', 'Jeju'];
// 'Joined' starts hidden. The ID cannot be hidden with the buttons below (an example of a column that must always show).
// Just put hidden: true in the column definition. A hidden column still remembers its sort, width and filter state.
export const options = {
columns: [
{ id: 'id', title: 'ID', width: 80, align: 'end' },
{ id: 'name', title: 'Name', width: 130 },
{ id: 'team', title: 'Team', width: 110 },
{ id: 'city', title: 'Office', width: 100 },
{ id: 'phone', title: 'Phone', width: 140 },
{ id: 'salary', title: 'Salary ($)', kind: 'number', width: 120, align: 'end' },
{ id: 'joined', title: 'Joined', width: 120, hidden: true },
],
headerGroups: [
{ id: 'person', title: 'Personal', children: ['name', 'team', 'city'] },
{ id: 'etc', title: 'Other info', children: ['phone', 'salary', 'joined'] },
],
rows: Array.from({ length: 12 }, (_, i) => ({
id: 1001 + i,
name: names[i % 8],
team: teams[(i * 3) % 4],
city: cities[(i * 2) % 5],
phone: `555-${String(2000 + i * 391).slice(0, 4)}-${String(5100 + i * 733).slice(0, 4)}`,
salary: 42000 + ((i * 370) % 2400) * 10,
joined: `20${18 + (i % 6)}-${String(1 + ((i * 5) % 12)).padStart(2, '0')}-${String(3 + ((i * 7) % 25)).padStart(2, '0')}`,
})),
rowKey: 'id',
// Columns can also be hidden from the header menu (⋮). It is the easiest way for users to hide them.
columnMenu: true,
};
export function setup(api, log) {
const off = api.on('columnVisibilityChanged', ({ columnId, hidden }) => {
const title = api.getColumns().find((c) => c.id === columnId)?.title ?? columnId;
const shown = api.getColumnState().filter((s) => !s.hidden).length;
log(`${title} ${hidden ? 'hidden' : 'shown'} · ${shown} columns visible now`);
});
return () => off();
}
// Switch the whole view at once: give only the list of columns to show and the rest are hidden. The ID shows in every view.
const VIEWS = {
initial: ['id', 'name', 'team', 'city', 'phone', 'salary'],
all: ['id', 'name', 'team', 'city', 'phone', 'salary', 'joined'],
summary: ['id', 'name', 'team'],
contact: ['id', 'name', 'phone', 'city'],
'hide-name': ['id', 'team', 'city', 'phone', 'salary', 'joined'],
'hide-team': ['id', 'name', 'city', 'phone', 'salary', 'joined'],
'hide-city': ['id', 'name', 'team', 'phone', 'salary', 'joined'],
'hide-phone': ['id', 'name', 'team', 'city', 'salary', 'joined'],
'hide-salary': ['id', 'name', 'team', 'city', 'phone', 'joined'],
};
export const actions = {
view: (api, value) => {
const show = new Set(VIEWS[value ?? 'initial'] ?? VIEWS.initial);
api.getColumns().forEach((c) => api.setColumnVisible(c.id, show.has(c.id)));
},
};<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Show only the columns you need</title>
</head>
<body>
<div class="toolbar">
<select aria-label="View" id="view">
<option value="initial" selected>Initial (Joined hidden)</option>
<option value="all">Everything</option>
<option value="summary">Summary only</option>
<option value="contact">Contact view</option>
<option value="hide-name">Hide Name</option>
<option value="hide-team">Hide Team</option>
<option value="hide-city">Hide City</option>
<option value="hide-phone">Hide Phone</option>
<option value="hide-salary">Hide Salary</option>
</select>
</div>
<div id="grid" style="height: 480px"></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 Parker',
'Olivia Reed',
'Ethan Brooks',
'Sophia Hayes',
'Mason Wright',
'Ava Morgan',
];
const teams = ['Dev', 'Design', 'Sales', 'HR'];
const cities = ['Seoul', 'Busan', 'Daegu', 'Gwangju', 'Jeju'];
// 'Joined' starts hidden. The ID cannot be hidden with the buttons below (an example of a column that must always show).
// Just put hidden: true in the column definition. A hidden column still remembers its sort, width and filter state.
const options = {
columns: [
{ id: 'id', title: 'ID', width: 80, align: 'end' },
{ id: 'name', title: 'Name', width: 130 },
{ id: 'team', title: 'Team', width: 110 },
{ id: 'city', title: 'Office', width: 100 },
{ id: 'phone', title: 'Phone', width: 140 },
{ id: 'salary', title: 'Salary ($)', kind: 'number', width: 120, align: 'end' },
{ id: 'joined', title: 'Joined', width: 120, hidden: true },
],
headerGroups: [
{ id: 'person', title: 'Personal', children: ['name', 'team', 'city'] },
{ id: 'etc', title: 'Other info', children: ['phone', 'salary', 'joined'] },
],
rows: Array.from({ length: 12 }, (_, i) => ({
id: 1001 + i,
name: names[i % 8],
team: teams[(i * 3) % 4],
city: cities[(i * 2) % 5],
phone: `555-${String(2000 + i * 391).slice(0, 4)}-${String(5100 + i * 733).slice(0, 4)}`,
salary: 42000 + ((i * 370) % 2400) * 10,
joined: `20${18 + (i % 6)}-${String(1 + ((i * 5) % 12)).padStart(2, '0')}-${String(3 + ((i * 7) % 25)).padStart(2, '0')}`,
})),
rowKey: 'id',
// Columns can also be hidden from the header menu (⋮). It is the easiest way for users to hide them.
columnMenu: true,
};
function setup(api, log) {
const off = api.on('columnVisibilityChanged', ({ columnId, hidden }) => {
const title = api.getColumns().find((c) => c.id === columnId)?.title ?? columnId;
const shown = api.getColumnState().filter((s) => !s.hidden).length;
log(`${title} ${hidden ? 'hidden' : 'shown'} · ${shown} columns visible now`);
});
return () => off();
}
// Switch the whole view at once: give only the list of columns to show and the rest are hidden. The ID shows in every view.
const VIEWS = {
initial: ['id', 'name', 'team', 'city', 'phone', 'salary'],
all: ['id', 'name', 'team', 'city', 'phone', 'salary', 'joined'],
summary: ['id', 'name', 'team'],
contact: ['id', 'name', 'phone', 'city'],
'hide-name': ['id', 'team', 'city', 'phone', 'salary', 'joined'],
'hide-team': ['id', 'name', 'city', 'phone', 'salary', 'joined'],
'hide-city': ['id', 'name', 'team', 'phone', 'salary', 'joined'],
'hide-phone': ['id', 'name', 'team', 'city', 'salary', 'joined'],
'hide-salary': ['id', 'name', 'team', 'city', 'phone', 'joined'],
};
const actions = {
view: (api, value) => {
const show = new Set(VIEWS[value ?? 'initial'] ?? VIEWS.initial);
api.getColumns().forEach((c) => api.setColumnVisible(c.id, show.has(c.id)));
},
};
options.ariaLabel = "Show only the columns you need";
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('view').addEventListener('change', (event) => actions.view(api, event.target.value));
</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="View"
disabled={!api}
onChange={(event) => api && actions.view(api, event.target.value)}
>
<option value="initial">Initial (Joined hidden)</option>
<option value="all">Everything</option>
<option value="summary">Summary only</option>
<option value="contact">Contact view</option>
<option value="hide-name">Hide Name</option>
<option value="hide-team">Hide Team</option>
<option value="hide-city">Hide City</option>
<option value="hide-phone">Hide Phone</option>
<option value="hide-salary">Hide Salary</option>
</select>
</div>
<Grid style={{ height: 480 }} 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;
phone: string;
salary: number;
joined: string;
}
const names = [
'Liam Carter',
'Emma Stone',
'Noah Parker',
'Olivia Reed',
'Ethan Brooks',
'Sophia Hayes',
'Mason Wright',
'Ava Morgan',
];
const teams = ['Dev', 'Design', 'Sales', 'HR'];
const cities = ['Seoul', 'Busan', 'Daegu', 'Gwangju', 'Jeju'];
// 'Joined' starts hidden. The ID cannot be hidden with the buttons below (an example of a column that must always show).
// Just put hidden: true in the column definition. A hidden column still remembers its sort, width and filter state.
export const options: GridOptions<Row> = {
columns: [
{ id: 'id', title: 'ID', width: 80, align: 'end' },
{ id: 'name', title: 'Name', width: 130 },
{ id: 'team', title: 'Team', width: 110 },
{ id: 'city', title: 'Office', width: 100 },
{ id: 'phone', title: 'Phone', width: 140 },
{ id: 'salary', title: 'Salary ($)', kind: 'number', width: 120, align: 'end' },
{ id: 'joined', title: 'Joined', width: 120, hidden: true },
],
headerGroups: [
{ id: 'person', title: 'Personal', children: ['name', 'team', 'city'] },
{ id: 'etc', title: 'Other info', children: ['phone', 'salary', 'joined'] },
],
rows: Array.from({ length: 12 }, (_, i) => ({
id: 1001 + i,
name: names[i % 8] as string,
team: teams[(i * 3) % 4] as string,
city: cities[(i * 2) % 5] as string,
phone: `555-${String(2000 + i * 391).slice(0, 4)}-${String(5100 + i * 733).slice(0, 4)}`,
salary: 42000 + ((i * 370) % 2400) * 10,
joined: `20${18 + (i % 6)}-${String(1 + ((i * 5) % 12)).padStart(2, '0')}-${String(3 + ((i * 7) % 25)).padStart(2, '0')}`,
})),
rowKey: 'id',
// Columns can also be hidden from the header menu (⋮). It is the easiest way for users to hide them.
columnMenu: true,
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
const off = api.on('columnVisibilityChanged', ({ columnId, hidden }) => {
const title = api.getColumns().find((c) => c.id === columnId)?.title ?? columnId;
const shown = api.getColumnState().filter((s) => !s.hidden).length;
log(`${title} ${hidden ? 'hidden' : 'shown'} · ${shown} columns visible now`);
});
return () => off();
}
// Switch the whole view at once: give only the list of columns to show and the rest are hidden. The ID shows in every view.
const VIEWS: Record<string, string[]> = {
initial: ['id', 'name', 'team', 'city', 'phone', 'salary'],
all: ['id', 'name', 'team', 'city', 'phone', 'salary', 'joined'],
summary: ['id', 'name', 'team'],
contact: ['id', 'name', 'phone', 'city'],
'hide-name': ['id', 'team', 'city', 'phone', 'salary', 'joined'],
'hide-team': ['id', 'name', 'city', 'phone', 'salary', 'joined'],
'hide-city': ['id', 'name', 'team', 'phone', 'salary', 'joined'],
'hide-phone': ['id', 'name', 'team', 'city', 'salary', 'joined'],
'hide-salary': ['id', 'name', 'team', 'city', 'phone', 'joined'],
};
export const actions = {
view: (api: GridApi<Row>, value?: string) => {
const show = new Set(VIEWS[value ?? 'initial'] ?? VIEWS.initial);
api.getColumns().forEach((c) => api.setColumnVisible(c.id, show.has(c.id)));
},
};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="View"
:disabled="!api"
@change="api && actions.view(api, ($event.target as HTMLSelectElement).value)"
>
<option value="initial" selected>Initial (Joined hidden)</option>
<option value="all">Everything</option>
<option value="summary">Summary only</option>
<option value="contact">Contact view</option>
<option value="hide-name">Hide Name</option>
<option value="hide-team">Hide Team</option>
<option value="hide-city">Hide City</option>
<option value="hide-phone">Hide Phone</option>
<option value="hide-salary">Hide Salary</option>
</select>
</div>
<Grid style="height: 480px" :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;
phone: string;
salary: number;
joined: string;
}
const names = [
'Liam Carter',
'Emma Stone',
'Noah Parker',
'Olivia Reed',
'Ethan Brooks',
'Sophia Hayes',
'Mason Wright',
'Ava Morgan',
];
const teams = ['Dev', 'Design', 'Sales', 'HR'];
const cities = ['Seoul', 'Busan', 'Daegu', 'Gwangju', 'Jeju'];
// 'Joined' starts hidden. The ID cannot be hidden with the buttons below (an example of a column that must always show).
// Just put hidden: true in the column definition. A hidden column still remembers its sort, width and filter state.
export const options: GridOptions<Row> = {
columns: [
{ id: 'id', title: 'ID', width: 80, align: 'end' },
{ id: 'name', title: 'Name', width: 130 },
{ id: 'team', title: 'Team', width: 110 },
{ id: 'city', title: 'Office', width: 100 },
{ id: 'phone', title: 'Phone', width: 140 },
{ id: 'salary', title: 'Salary ($)', kind: 'number', width: 120, align: 'end' },
{ id: 'joined', title: 'Joined', width: 120, hidden: true },
],
headerGroups: [
{ id: 'person', title: 'Personal', children: ['name', 'team', 'city'] },
{ id: 'etc', title: 'Other info', children: ['phone', 'salary', 'joined'] },
],
rows: Array.from({ length: 12 }, (_, i) => ({
id: 1001 + i,
name: names[i % 8] as string,
team: teams[(i * 3) % 4] as string,
city: cities[(i * 2) % 5] as string,
phone: `555-${String(2000 + i * 391).slice(0, 4)}-${String(5100 + i * 733).slice(0, 4)}`,
salary: 42000 + ((i * 370) % 2400) * 10,
joined: `20${18 + (i % 6)}-${String(1 + ((i * 5) % 12)).padStart(2, '0')}-${String(3 + ((i * 7) % 25)).padStart(2, '0')}`,
})),
rowKey: 'id',
// Columns can also be hidden from the header menu (⋮). It is the easiest way for users to hide them.
columnMenu: true,
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
const off = api.on('columnVisibilityChanged', ({ columnId, hidden }) => {
const title = api.getColumns().find((c) => c.id === columnId)?.title ?? columnId;
const shown = api.getColumnState().filter((s) => !s.hidden).length;
log(`${title} ${hidden ? 'hidden' : 'shown'} · ${shown} columns visible now`);
});
return () => off();
}
// Switch the whole view at once: give only the list of columns to show and the rest are hidden. The ID shows in every view.
const VIEWS: Record<string, string[]> = {
initial: ['id', 'name', 'team', 'city', 'phone', 'salary'],
all: ['id', 'name', 'team', 'city', 'phone', 'salary', 'joined'],
summary: ['id', 'name', 'team'],
contact: ['id', 'name', 'phone', 'city'],
'hide-name': ['id', 'team', 'city', 'phone', 'salary', 'joined'],
'hide-team': ['id', 'name', 'city', 'phone', 'salary', 'joined'],
'hide-city': ['id', 'name', 'team', 'phone', 'salary', 'joined'],
'hide-phone': ['id', 'name', 'team', 'city', 'salary', 'joined'],
'hide-salary': ['id', 'name', 'team', 'city', 'phone', 'joined'],
};
export const actions = {
view: (api: GridApi<Row>, value?: string) => {
const show = new Set(VIEWS[value ?? 'initial'] ?? VIEWS.initial);
api.getColumns().forEach((c) => api.setColumnVisible(c.id, show.has(c.id)));
},
};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="View"
[disabled]="!api"
(change)="api && actions.view(api, $any($event.target).value)"
>
<option value="initial" selected>Initial (Joined hidden)</option>
<option value="all">Everything</option>
<option value="summary">Summary only</option>
<option value="contact">Contact view</option>
<option value="hide-name">Hide Name</option>
<option value="hide-team">Hide Team</option>
<option value="hide-city">Hide City</option>
<option value="hide-phone">Hide Phone</option>
<option value="hide-salary">Hide Salary</option>
</select>
</div>
<mx-grid style="height: 480px" [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;
phone: string;
salary: number;
joined: string;
}
const names = [
'Liam Carter',
'Emma Stone',
'Noah Parker',
'Olivia Reed',
'Ethan Brooks',
'Sophia Hayes',
'Mason Wright',
'Ava Morgan',
];
const teams = ['Dev', 'Design', 'Sales', 'HR'];
const cities = ['Seoul', 'Busan', 'Daegu', 'Gwangju', 'Jeju'];
// 'Joined' starts hidden. The ID cannot be hidden with the buttons below (an example of a column that must always show).
// Just put hidden: true in the column definition. A hidden column still remembers its sort, width and filter state.
export const options: GridOptions<Row> = {
columns: [
{ id: 'id', title: 'ID', width: 80, align: 'end' },
{ id: 'name', title: 'Name', width: 130 },
{ id: 'team', title: 'Team', width: 110 },
{ id: 'city', title: 'Office', width: 100 },
{ id: 'phone', title: 'Phone', width: 140 },
{ id: 'salary', title: 'Salary ($)', kind: 'number', width: 120, align: 'end' },
{ id: 'joined', title: 'Joined', width: 120, hidden: true },
],
headerGroups: [
{ id: 'person', title: 'Personal', children: ['name', 'team', 'city'] },
{ id: 'etc', title: 'Other info', children: ['phone', 'salary', 'joined'] },
],
rows: Array.from({ length: 12 }, (_, i) => ({
id: 1001 + i,
name: names[i % 8] as string,
team: teams[(i * 3) % 4] as string,
city: cities[(i * 2) % 5] as string,
phone: `555-${String(2000 + i * 391).slice(0, 4)}-${String(5100 + i * 733).slice(0, 4)}`,
salary: 42000 + ((i * 370) % 2400) * 10,
joined: `20${18 + (i % 6)}-${String(1 + ((i * 5) % 12)).padStart(2, '0')}-${String(3 + ((i * 7) % 25)).padStart(2, '0')}`,
})),
rowKey: 'id',
// Columns can also be hidden from the header menu (⋮). It is the easiest way for users to hide them.
columnMenu: true,
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
const off = api.on('columnVisibilityChanged', ({ columnId, hidden }) => {
const title = api.getColumns().find((c) => c.id === columnId)?.title ?? columnId;
const shown = api.getColumnState().filter((s) => !s.hidden).length;
log(`${title} ${hidden ? 'hidden' : 'shown'} · ${shown} columns visible now`);
});
return () => off();
}
// Switch the whole view at once: give only the list of columns to show and the rest are hidden. The ID shows in every view.
const VIEWS: Record<string, string[]> = {
initial: ['id', 'name', 'team', 'city', 'phone', 'salary'],
all: ['id', 'name', 'team', 'city', 'phone', 'salary', 'joined'],
summary: ['id', 'name', 'team'],
contact: ['id', 'name', 'phone', 'city'],
'hide-name': ['id', 'team', 'city', 'phone', 'salary', 'joined'],
'hide-team': ['id', 'name', 'city', 'phone', 'salary', 'joined'],
'hide-city': ['id', 'name', 'team', 'phone', 'salary', 'joined'],
'hide-phone': ['id', 'name', 'team', 'city', 'salary', 'joined'],
'hide-salary': ['id', 'name', 'team', 'city', 'phone', 'joined'],
};
export const actions = {
view: (api: GridApi<Row>, value?: string) => {
const show = new Set(VIEWS[value ?? 'initial'] ?? VIEWS.initial);
api.getColumns().forEach((c) => api.setColumnVisible(c.id, show.has(c.id)));
},
};