고정 컬럼을 한 번에 정하기Set the pinned columns at once
pinColumns는 왼쪽·오른쪽 고정 컬럼 전체를 한 번에 정해요. 적은 순서가 영역 안 순서이고, 이름이 없는 컬럼은 고정이 풀려요. showAllColumns는 숨긴 컬럼을 한꺼번에 다시 보여요.pinColumns sets the whole pinned set in one call. The given order is the order inside each zone, and unnamed columns are unpinned. showAllColumns brings every hidden column back.
코드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="both">양쪽 고정</button>
<button type="button" id="none">모두 풀기</button>
<button type="button" id="hide">이름·팀 숨기기</button>
<button type="button" id="all">숨긴 것 모두 보이기</button>
</div>
<div id="grid" style="height: 220px"></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('both').addEventListener('click', () => actions.both(api));
document.getElementById('none').addEventListener('click', () => actions.none(api));
document.getElementById('hide').addEventListener('click', () => actions.hide(api));
document.getElementById('all').addEventListener('click', () => actions.all(api));const COLUMNS = [
{ id: 'id', title: '사번', width: 80, align: 'end' },
{ id: 'name', title: '이름', width: 110 },
{ id: 'team', title: '팀', width: 110 },
{ id: 'city', title: '근무지', width: 100 },
{ id: 'salary', title: '연봉(만원)', kind: 'number', width: 120, align: 'end' },
];
const ROWS = [
{ id: 1001, name: '김민준', team: '개발팀', city: '서울', salary: 6200 },
{ id: 1002, name: '이서연', team: '디자인팀', city: '부산', salary: 4800 },
{ id: 1003, name: '박지호', team: '영업팀', city: '대구', salary: 7100 },
{ id: 1004, name: '최유나', team: '인사팀', city: '서울', salary: 3900 },
];
let say = () => { };
export const options = {
columns: COLUMNS.map((c) => ({ ...c, width: 220 })),
rows: ROWS,
rowKey: 'id',
};
export function setup(_api, log) {
say = log;
return () => { };
}
export const actions = {
both: (api) => {
api.pinColumns({ start: ['id', 'name'], end: ['salary'] });
say({
ko: '왼쪽 사번·이름, 오른쪽 연봉을 고정했어요',
en: 'Pinned id and name left, salary right',
});
},
none: (api) => {
api.pinColumns({});
say({ ko: '고정을 모두 풀었어요', en: 'Unpinned everything' });
},
hide: (api) => {
api.setColumnVisible('name', false);
api.setColumnVisible('team', false);
},
all: (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">
<button type="button" id="both">양쪽 고정</button>
<button type="button" id="none">모두 풀기</button>
<button type="button" id="hide">이름·팀 숨기기</button>
<button type="button" id="all">숨긴 것 모두 보이기</button>
</div>
<div id="grid" style="height: 220px"></div>
<ul id="log" aria-live="polite"></ul>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script>
const COLUMNS = [
{ id: 'id', title: '사번', width: 80, align: 'end' },
{ id: 'name', title: '이름', width: 110 },
{ id: 'team', title: '팀', width: 110 },
{ id: 'city', title: '근무지', width: 100 },
{ id: 'salary', title: '연봉(만원)', kind: 'number', width: 120, align: 'end' },
];
const ROWS = [
{ id: 1001, name: '김민준', team: '개발팀', city: '서울', salary: 6200 },
{ id: 1002, name: '이서연', team: '디자인팀', city: '부산', salary: 4800 },
{ id: 1003, name: '박지호', team: '영업팀', city: '대구', salary: 7100 },
{ id: 1004, name: '최유나', team: '인사팀', city: '서울', salary: 3900 },
];
let say = () => { };
const options = {
columns: COLUMNS.map((c) => ({ ...c, width: 220 })),
rows: ROWS,
rowKey: 'id',
};
function setup(_api, log) {
say = log;
return () => { };
}
const actions = {
both: (api) => {
api.pinColumns({ start: ['id', 'name'], end: ['salary'] });
say({
ko: '왼쪽 사번·이름, 오른쪽 연봉을 고정했어요',
en: 'Pinned id and name left, salary right',
});
},
none: (api) => {
api.pinColumns({});
say({ ko: '고정을 모두 풀었어요', en: 'Unpinned everything' });
},
hide: (api) => {
api.setColumnVisible('name', false);
api.setColumnVisible('team', false);
},
all: (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('both').addEventListener('click', () => actions.both(api));
document.getElementById('none').addEventListener('click', () => actions.none(api));
document.getElementById('hide').addEventListener('click', () => actions.hide(api));
document.getElementById('all').addEventListener('click', () => actions.all(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.both(api)}
>양쪽 고정</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.none(api)}
>모두 풀기</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.hide(api)}
>이름·팀 숨기기</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.all(api)}
>숨긴 것 모두 보이기</button>
</div>
<Grid style={{ height: 220 }} ref={gridRef} options={options} />
</>
);
}import type { ColumnDef, GridApi, GridOptions } from '@maxgrid/react';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
name: string;
team: string;
city: string;
salary: number;
}
const COLUMNS: ColumnDef<Row>[] = [
{ id: 'id', title: '사번', width: 80, align: 'end' },
{ id: 'name', title: '이름', width: 110 },
{ id: 'team', title: '팀', width: 110 },
{ id: 'city', title: '근무지', width: 100 },
{ id: 'salary', title: '연봉(만원)', kind: 'number', width: 120, align: 'end' },
];
const ROWS: Row[] = [
{ id: 1001, name: '김민준', team: '개발팀', city: '서울', salary: 6200 },
{ id: 1002, name: '이서연', team: '디자인팀', city: '부산', salary: 4800 },
{ id: 1003, name: '박지호', team: '영업팀', city: '대구', salary: 7100 },
{ id: 1004, name: '최유나', team: '인사팀', city: '서울', salary: 3900 },
];
let say: (message: LogText) => void = () => {};
export const options: GridOptions<Row> = {
columns: COLUMNS.map((c) => ({ ...c, width: 220 })),
rows: ROWS,
rowKey: 'id',
};
export function setup(_api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
return () => {};
}
export const actions = {
both: (api: GridApi<Row>) => {
api.pinColumns({ start: ['id', 'name'], end: ['salary'] });
say({
ko: '왼쪽 사번·이름, 오른쪽 연봉을 고정했어요',
en: 'Pinned id and name left, salary right',
});
},
none: (api: GridApi<Row>) => {
api.pinColumns({});
say({ ko: '고정을 모두 풀었어요', en: 'Unpinned everything' });
},
hide: (api: GridApi<Row>) => {
api.setColumnVisible('name', false);
api.setColumnVisible('team', false);
},
all: (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">
<button type="button" :disabled="!api" @click="api && actions.both(api)">양쪽 고정</button>
<button type="button" :disabled="!api" @click="api && actions.none(api)">모두 풀기</button>
<button type="button" :disabled="!api" @click="api && actions.hide(api)">이름·팀 숨기기</button>
<button type="button" :disabled="!api" @click="api && actions.all(api)">숨긴 것 모두 보이기</button>
</div>
<Grid style="height: 220px" :options="options" @ready="onReady" />
</template>import type { ColumnDef, GridApi, GridOptions } from '@maxgrid/vue';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
name: string;
team: string;
city: string;
salary: number;
}
const COLUMNS: ColumnDef<Row>[] = [
{ id: 'id', title: '사번', width: 80, align: 'end' },
{ id: 'name', title: '이름', width: 110 },
{ id: 'team', title: '팀', width: 110 },
{ id: 'city', title: '근무지', width: 100 },
{ id: 'salary', title: '연봉(만원)', kind: 'number', width: 120, align: 'end' },
];
const ROWS: Row[] = [
{ id: 1001, name: '김민준', team: '개발팀', city: '서울', salary: 6200 },
{ id: 1002, name: '이서연', team: '디자인팀', city: '부산', salary: 4800 },
{ id: 1003, name: '박지호', team: '영업팀', city: '대구', salary: 7100 },
{ id: 1004, name: '최유나', team: '인사팀', city: '서울', salary: 3900 },
];
let say: (message: LogText) => void = () => {};
export const options: GridOptions<Row> = {
columns: COLUMNS.map((c) => ({ ...c, width: 220 })),
rows: ROWS,
rowKey: 'id',
};
export function setup(_api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
return () => {};
}
export const actions = {
both: (api: GridApi<Row>) => {
api.pinColumns({ start: ['id', 'name'], end: ['salary'] });
say({
ko: '왼쪽 사번·이름, 오른쪽 연봉을 고정했어요',
en: 'Pinned id and name left, salary right',
});
},
none: (api: GridApi<Row>) => {
api.pinColumns({});
say({ ko: '고정을 모두 풀었어요', en: 'Unpinned everything' });
},
hide: (api: GridApi<Row>) => {
api.setColumnVisible('name', false);
api.setColumnVisible('team', false);
},
all: (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">
<button
type="button"
[disabled]="!api"
(click)="api && actions.both(api)"
>양쪽 고정</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.none(api)"
>모두 풀기</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.hide(api)"
>이름·팀 숨기기</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.all(api)"
>숨긴 것 모두 보이기</button>
</div>
<mx-grid style="height: 220px" [options]="options" [events]="relayed" (gridEvent)="onEvent($event)" />
`,
})
export class ExampleGridComponent implements OnDestroy {
readonly options = options;
readonly actions = actions;
readonly relayed = ['ready'] as const;
api: GridApi<Row> | null = null;
private stop: (() => void) | null = null;
onEvent(event: GridEventMessage<Row>): void {
if (isGridEvent(event, 'ready')) {
this.api = event.payload.api;
this.stop = setup(this.api, console.log);
}
}
ngOnDestroy(): void {
this.stop?.();
}
}import type { ColumnDef, GridApi, GridOptions } from '@maxgrid/angular';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
name: string;
team: string;
city: string;
salary: number;
}
const COLUMNS: ColumnDef<Row>[] = [
{ id: 'id', title: '사번', width: 80, align: 'end' },
{ id: 'name', title: '이름', width: 110 },
{ id: 'team', title: '팀', width: 110 },
{ id: 'city', title: '근무지', width: 100 },
{ id: 'salary', title: '연봉(만원)', kind: 'number', width: 120, align: 'end' },
];
const ROWS: Row[] = [
{ id: 1001, name: '김민준', team: '개발팀', city: '서울', salary: 6200 },
{ id: 1002, name: '이서연', team: '디자인팀', city: '부산', salary: 4800 },
{ id: 1003, name: '박지호', team: '영업팀', city: '대구', salary: 7100 },
{ id: 1004, name: '최유나', team: '인사팀', city: '서울', salary: 3900 },
];
let say: (message: LogText) => void = () => {};
export const options: GridOptions<Row> = {
columns: COLUMNS.map((c) => ({ ...c, width: 220 })),
rows: ROWS,
rowKey: 'id',
};
export function setup(_api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
return () => {};
}
export const actions = {
both: (api: GridApi<Row>) => {
api.pinColumns({ start: ['id', 'name'], end: ['salary'] });
say({
ko: '왼쪽 사번·이름, 오른쪽 연봉을 고정했어요',
en: 'Pinned id and name left, salary right',
});
},
none: (api: GridApi<Row>) => {
api.pinColumns({});
say({ ko: '고정을 모두 풀었어요', en: 'Unpinned everything' });
},
hide: (api: GridApi<Row>) => {
api.setColumnVisible('name', false);
api.setColumnVisible('team', false);
},
all: (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">
<button type="button" id="both">Pin both sides</button>
<button type="button" id="none">Unpin all</button>
<button type="button" id="hide">Hide Name and Team</button>
<button type="button" id="all">Show all</button>
</div>
<div id="grid" style="height: 220px"></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('both').addEventListener('click', () => actions.both(api));
document.getElementById('none').addEventListener('click', () => actions.none(api));
document.getElementById('hide').addEventListener('click', () => actions.hide(api));
document.getElementById('all').addEventListener('click', () => actions.all(api));const COLUMNS = [
{ id: 'id', title: 'Emp ID', width: 90, align: 'end' },
{ id: 'name', title: 'Name', width: 110 },
{ id: 'team', title: 'Team', width: 110 },
{ id: 'city', title: 'Office', width: 100 },
{ id: 'salary', title: 'Salary ($)', kind: 'number', width: 120, align: 'end' },
];
const ROWS = [
{ id: 1001, name: 'Liam Carter', team: 'Dev', city: 'Seattle', salary: 62000 },
{ id: 1002, name: 'Emma Stone', team: 'Design', city: 'Boston', salary: 48000 },
{ id: 1003, name: 'Noah Hayes', team: 'Sales', city: 'Denver', salary: 71000 },
{ id: 1004, name: 'Olivia Reed', team: 'HR', city: 'Seattle', salary: 39000 },
];
let say = () => { };
export const options = {
columns: COLUMNS.map((c) => ({ ...c, width: 220 })),
rows: ROWS,
rowKey: 'id',
};
export function setup(_api, log) {
say = log;
return () => { };
}
export const actions = {
both: (api) => {
api.pinColumns({ start: ['id', 'name'], end: ['salary'] });
say('Pinned id and name left, salary right');
},
none: (api) => {
api.pinColumns({});
say('Unpinned everything');
},
hide: (api) => {
api.setColumnVisible('name', false);
api.setColumnVisible('team', false);
},
all: (api) => api.showAllColumns(),
};<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Set the pinned columns at once</title>
</head>
<body>
<div class="toolbar">
<button type="button" id="both">Pin both sides</button>
<button type="button" id="none">Unpin all</button>
<button type="button" id="hide">Hide Name and Team</button>
<button type="button" id="all">Show all</button>
</div>
<div id="grid" style="height: 220px"></div>
<ul id="log" aria-live="polite"></ul>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script>
const COLUMNS = [
{ id: 'id', title: 'Emp ID', width: 90, align: 'end' },
{ id: 'name', title: 'Name', width: 110 },
{ id: 'team', title: 'Team', width: 110 },
{ id: 'city', title: 'Office', width: 100 },
{ id: 'salary', title: 'Salary ($)', kind: 'number', width: 120, align: 'end' },
];
const ROWS = [
{ id: 1001, name: 'Liam Carter', team: 'Dev', city: 'Seattle', salary: 62000 },
{ id: 1002, name: 'Emma Stone', team: 'Design', city: 'Boston', salary: 48000 },
{ id: 1003, name: 'Noah Hayes', team: 'Sales', city: 'Denver', salary: 71000 },
{ id: 1004, name: 'Olivia Reed', team: 'HR', city: 'Seattle', salary: 39000 },
];
let say = () => { };
const options = {
columns: COLUMNS.map((c) => ({ ...c, width: 220 })),
rows: ROWS,
rowKey: 'id',
};
function setup(_api, log) {
say = log;
return () => { };
}
const actions = {
both: (api) => {
api.pinColumns({ start: ['id', 'name'], end: ['salary'] });
say('Pinned id and name left, salary right');
},
none: (api) => {
api.pinColumns({});
say('Unpinned everything');
},
hide: (api) => {
api.setColumnVisible('name', false);
api.setColumnVisible('team', false);
},
all: (api) => api.showAllColumns(),
};
options.ariaLabel = "Set the pinned columns at once";
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('both').addEventListener('click', () => actions.both(api));
document.getElementById('none').addEventListener('click', () => actions.none(api));
document.getElementById('hide').addEventListener('click', () => actions.hide(api));
document.getElementById('all').addEventListener('click', () => actions.all(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.both(api)}
>Pin both sides</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.none(api)}
>Unpin all</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.hide(api)}
>Hide Name and Team</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.all(api)}
>Show all</button>
</div>
<Grid style={{ height: 220 }} ref={gridRef} options={options} />
</>
);
}import type { ColumnDef, GridApi, GridOptions } from '@maxgrid/react';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
name: string;
team: string;
city: string;
salary: number;
}
const COLUMNS: ColumnDef<Row>[] = [
{ id: 'id', title: 'Emp ID', width: 90, align: 'end' },
{ id: 'name', title: 'Name', width: 110 },
{ id: 'team', title: 'Team', width: 110 },
{ id: 'city', title: 'Office', width: 100 },
{ id: 'salary', title: 'Salary ($)', kind: 'number', width: 120, align: 'end' },
];
const ROWS: Row[] = [
{ id: 1001, name: 'Liam Carter', team: 'Dev', city: 'Seattle', salary: 62000 },
{ id: 1002, name: 'Emma Stone', team: 'Design', city: 'Boston', salary: 48000 },
{ id: 1003, name: 'Noah Hayes', team: 'Sales', city: 'Denver', salary: 71000 },
{ id: 1004, name: 'Olivia Reed', team: 'HR', city: 'Seattle', salary: 39000 },
];
let say: (message: LogText) => void = () => {};
export const options: GridOptions<Row> = {
columns: COLUMNS.map((c) => ({ ...c, width: 220 })),
rows: ROWS,
rowKey: 'id',
};
export function setup(_api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
return () => {};
}
export const actions = {
both: (api: GridApi<Row>) => {
api.pinColumns({ start: ['id', 'name'], end: ['salary'] });
say('Pinned id and name left, salary right');
},
none: (api: GridApi<Row>) => {
api.pinColumns({});
say('Unpinned everything');
},
hide: (api: GridApi<Row>) => {
api.setColumnVisible('name', false);
api.setColumnVisible('team', false);
},
all: (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">
<button type="button" :disabled="!api" @click="api && actions.both(api)">Pin both sides</button>
<button type="button" :disabled="!api" @click="api && actions.none(api)">Unpin all</button>
<button type="button" :disabled="!api" @click="api && actions.hide(api)">Hide Name and Team</button>
<button type="button" :disabled="!api" @click="api && actions.all(api)">Show all</button>
</div>
<Grid style="height: 220px" :options="options" @ready="onReady" />
</template>import type { ColumnDef, GridApi, GridOptions } from '@maxgrid/vue';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
name: string;
team: string;
city: string;
salary: number;
}
const COLUMNS: ColumnDef<Row>[] = [
{ id: 'id', title: 'Emp ID', width: 90, align: 'end' },
{ id: 'name', title: 'Name', width: 110 },
{ id: 'team', title: 'Team', width: 110 },
{ id: 'city', title: 'Office', width: 100 },
{ id: 'salary', title: 'Salary ($)', kind: 'number', width: 120, align: 'end' },
];
const ROWS: Row[] = [
{ id: 1001, name: 'Liam Carter', team: 'Dev', city: 'Seattle', salary: 62000 },
{ id: 1002, name: 'Emma Stone', team: 'Design', city: 'Boston', salary: 48000 },
{ id: 1003, name: 'Noah Hayes', team: 'Sales', city: 'Denver', salary: 71000 },
{ id: 1004, name: 'Olivia Reed', team: 'HR', city: 'Seattle', salary: 39000 },
];
let say: (message: LogText) => void = () => {};
export const options: GridOptions<Row> = {
columns: COLUMNS.map((c) => ({ ...c, width: 220 })),
rows: ROWS,
rowKey: 'id',
};
export function setup(_api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
return () => {};
}
export const actions = {
both: (api: GridApi<Row>) => {
api.pinColumns({ start: ['id', 'name'], end: ['salary'] });
say('Pinned id and name left, salary right');
},
none: (api: GridApi<Row>) => {
api.pinColumns({});
say('Unpinned everything');
},
hide: (api: GridApi<Row>) => {
api.setColumnVisible('name', false);
api.setColumnVisible('team', false);
},
all: (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">
<button
type="button"
[disabled]="!api"
(click)="api && actions.both(api)"
>Pin both sides</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.none(api)"
>Unpin all</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.hide(api)"
>Hide Name and Team</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.all(api)"
>Show all</button>
</div>
<mx-grid style="height: 220px" [options]="options" [events]="relayed" (gridEvent)="onEvent($event)" />
`,
})
export class ExampleGridComponent implements OnDestroy {
readonly options = options;
readonly actions = actions;
readonly relayed = ['ready'] as const;
api: GridApi<Row> | null = null;
private stop: (() => void) | null = null;
onEvent(event: GridEventMessage<Row>): void {
if (isGridEvent(event, 'ready')) {
this.api = event.payload.api;
this.stop = setup(this.api, console.log);
}
}
ngOnDestroy(): void {
this.stop?.();
}
}import type { ColumnDef, GridApi, GridOptions } from '@maxgrid/angular';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
name: string;
team: string;
city: string;
salary: number;
}
const COLUMNS: ColumnDef<Row>[] = [
{ id: 'id', title: 'Emp ID', width: 90, align: 'end' },
{ id: 'name', title: 'Name', width: 110 },
{ id: 'team', title: 'Team', width: 110 },
{ id: 'city', title: 'Office', width: 100 },
{ id: 'salary', title: 'Salary ($)', kind: 'number', width: 120, align: 'end' },
];
const ROWS: Row[] = [
{ id: 1001, name: 'Liam Carter', team: 'Dev', city: 'Seattle', salary: 62000 },
{ id: 1002, name: 'Emma Stone', team: 'Design', city: 'Boston', salary: 48000 },
{ id: 1003, name: 'Noah Hayes', team: 'Sales', city: 'Denver', salary: 71000 },
{ id: 1004, name: 'Olivia Reed', team: 'HR', city: 'Seattle', salary: 39000 },
];
let say: (message: LogText) => void = () => {};
export const options: GridOptions<Row> = {
columns: COLUMNS.map((c) => ({ ...c, width: 220 })),
rows: ROWS,
rowKey: 'id',
};
export function setup(_api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
return () => {};
}
export const actions = {
both: (api: GridApi<Row>) => {
api.pinColumns({ start: ['id', 'name'], end: ['salary'] });
say('Pinned id and name left, salary right');
},
none: (api: GridApi<Row>) => {
api.pinColumns({});
say('Unpinned everything');
},
hide: (api: GridApi<Row>) => {
api.setColumnVisible('name', false);
api.setColumnVisible('team', false);
},
all: (api: GridApi<Row>) => api.showAllColumns(),
};