머리글에 버튼 넣기Put a button in a header
컬럼의 headerRenderer: 'button'은 머리글 제목 옆에 버튼을 넣어요. label, onClick, position, disabled를 headerRendererParams로 줘요. 버튼을 눌러도 정렬·끌기·크기 조절·메뉴는 일어나지 않고, 정렬이 꺼진 컬럼은 머리글에 포커스를 둔 채 Enter·Space로도 눌러요.A column's headerRenderer: 'button' puts a button next to the header title. label, onClick, position and disabled go in headerRendererParams. Pressing it does not sort, drag, resize or open the menu, and on a column without sorting Enter and Space press it while the header is focused.
코드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="reset">되돌리기</button>
</div>
<div id="grid" style="height: 200px"></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('reset').addEventListener('click', () => actions.reset(api));const rows = [
{ id: 1, task: '로그인 화면 수정', owner: '김하늘', done: false },
{ id: 2, task: '결제 흐름 검토', owner: '이도윤', done: true },
{ id: 3, task: '새 아이콘 세트', owner: '박서연', done: false },
{ id: 4, task: '배포 점검', owner: '최지우', done: false },
];
// headerRenderer: 'button'은 머리글 제목 옆에 버튼을 넣어요. 누르면 정렬·끌기·메뉴는 일어나지 않고 onClick만 불려요.
// 정렬이 꺼진 컬럼은 머리글에 포커스를 두고(Tab 대신 focusHeader) Enter·Space로도 눌러요.
export function setup(api, log) {
const params = {
label: '모두 완료로',
onClick: () => {
api.updateRows(api.getRows().map((row) => ({ ...row, done: true })));
log({ ko: '모든 작업을 완료로 바꿨어요.', en: 'All tasks are marked done.' });
api.setHeaderRendererParams('done', params); // 속성을 다시 알려 머리글을 다시 그려요(disabled를 다시 평가)
},
// 이미 모두 완료이면 막아요. 값은 머리글을 그릴 때 평가돼요.
disabled: () => api.getRows().every((row) => row.done),
};
api.setColumns([
{ id: 'task', title: '작업', width: 170, sortable: true },
{ id: 'owner', title: '담당', width: 100, sortable: true },
{
id: 'done',
title: '완료',
kind: 'boolean',
width: 190,
sortable: false,
headerRenderer: 'button',
headerRendererParams: params,
},
]);
log({
ko: '"완료" 머리글의 버튼을 눌러 보세요. 한 번 누르면 버튼이 비활성이 돼요.',
en: 'Press the button in the Done header. After one press it becomes disabled.',
});
}
export const options = { columns: [{ id: 'task' }], rows, rowKey: 'id' };
export const actions = {
reset: (api) => {
api.updateRows(api.getRows().map((row) => ({ ...row, done: false })));
api.updateColumn('done', {
headerRendererParams: api.getColumns().find((c) => c.id === 'done')?.headerRendererParams,
});
},
};<!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="reset">되돌리기</button>
</div>
<div id="grid" style="height: 200px"></div>
<ul id="log" aria-live="polite"></ul>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script>
const rows = [
{ id: 1, task: '로그인 화면 수정', owner: '김하늘', done: false },
{ id: 2, task: '결제 흐름 검토', owner: '이도윤', done: true },
{ id: 3, task: '새 아이콘 세트', owner: '박서연', done: false },
{ id: 4, task: '배포 점검', owner: '최지우', done: false },
];
// headerRenderer: 'button'은 머리글 제목 옆에 버튼을 넣어요. 누르면 정렬·끌기·메뉴는 일어나지 않고 onClick만 불려요.
// 정렬이 꺼진 컬럼은 머리글에 포커스를 두고(Tab 대신 focusHeader) Enter·Space로도 눌러요.
function setup(api, log) {
const params = {
label: '모두 완료로',
onClick: () => {
api.updateRows(api.getRows().map((row) => ({ ...row, done: true })));
log({ ko: '모든 작업을 완료로 바꿨어요.', en: 'All tasks are marked done.' });
api.setHeaderRendererParams('done', params); // 속성을 다시 알려 머리글을 다시 그려요(disabled를 다시 평가)
},
// 이미 모두 완료이면 막아요. 값은 머리글을 그릴 때 평가돼요.
disabled: () => api.getRows().every((row) => row.done),
};
api.setColumns([
{ id: 'task', title: '작업', width: 170, sortable: true },
{ id: 'owner', title: '담당', width: 100, sortable: true },
{
id: 'done',
title: '완료',
kind: 'boolean',
width: 190,
sortable: false,
headerRenderer: 'button',
headerRendererParams: params,
},
]);
log({
ko: '"완료" 머리글의 버튼을 눌러 보세요. 한 번 누르면 버튼이 비활성이 돼요.',
en: 'Press the button in the Done header. After one press it becomes disabled.',
});
}
const options = { columns: [{ id: 'task' }], rows, rowKey: 'id' };
const actions = {
reset: (api) => {
api.updateRows(api.getRows().map((row) => ({ ...row, done: false })));
api.updateColumn('done', {
headerRendererParams: api.getColumns().find((c) => c.id === 'done')?.headerRendererParams,
});
},
};
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('reset').addEventListener('click', () => actions.reset(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.reset(api)}
>되돌리기</button>
</div>
<Grid style={{ height: 200 }} ref={gridRef} options={options} />
</>
);
}import type { GridApi, GridOptions } from '@maxgrid/react';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
task: string;
owner: string;
done: boolean;
}
const rows: Row[] = [
{ id: 1, task: '로그인 화면 수정', owner: '김하늘', done: false },
{ id: 2, task: '결제 흐름 검토', owner: '이도윤', done: true },
{ id: 3, task: '새 아이콘 세트', owner: '박서연', done: false },
{ id: 4, task: '배포 점검', owner: '최지우', done: false },
];
// headerRenderer: 'button'은 머리글 제목 옆에 버튼을 넣어요. 누르면 정렬·끌기·메뉴는 일어나지 않고 onClick만 불려요.
// 정렬이 꺼진 컬럼은 머리글에 포커스를 두고(Tab 대신 focusHeader) Enter·Space로도 눌러요.
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
const params = {
label: '모두 완료로',
onClick: () => {
api.updateRows(api.getRows().map((row) => ({ ...row, done: true })));
log({ ko: '모든 작업을 완료로 바꿨어요.', en: 'All tasks are marked done.' });
api.setHeaderRendererParams('done', params); // 속성을 다시 알려 머리글을 다시 그려요(disabled를 다시 평가)
},
// 이미 모두 완료이면 막아요. 값은 머리글을 그릴 때 평가돼요.
disabled: () => api.getRows().every((row) => row.done),
};
api.setColumns([
{ id: 'task', title: '작업', width: 170, sortable: true },
{ id: 'owner', title: '담당', width: 100, sortable: true },
{
id: 'done',
title: '완료',
kind: 'boolean',
width: 190,
sortable: false,
headerRenderer: 'button',
headerRendererParams: params,
},
]);
log({
ko: '"완료" 머리글의 버튼을 눌러 보세요. 한 번 누르면 버튼이 비활성이 돼요.',
en: 'Press the button in the Done header. After one press it becomes disabled.',
});
}
export const options: GridOptions<Row> = { columns: [{ id: 'task' }], rows, rowKey: 'id' };
export const actions = {
reset: (api: GridApi<Row>) => {
api.updateRows(api.getRows().map((row) => ({ ...row, done: false })));
api.updateColumn('done', {
headerRendererParams: api.getColumns().find((c) => c.id === 'done')?.headerRendererParams,
});
},
};버튼을 누르면 이 예제의 코드가 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.reset(api)">되돌리기</button>
</div>
<Grid style="height: 200px" :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;
task: string;
owner: string;
done: boolean;
}
const rows: Row[] = [
{ id: 1, task: '로그인 화면 수정', owner: '김하늘', done: false },
{ id: 2, task: '결제 흐름 검토', owner: '이도윤', done: true },
{ id: 3, task: '새 아이콘 세트', owner: '박서연', done: false },
{ id: 4, task: '배포 점검', owner: '최지우', done: false },
];
// headerRenderer: 'button'은 머리글 제목 옆에 버튼을 넣어요. 누르면 정렬·끌기·메뉴는 일어나지 않고 onClick만 불려요.
// 정렬이 꺼진 컬럼은 머리글에 포커스를 두고(Tab 대신 focusHeader) Enter·Space로도 눌러요.
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
const params = {
label: '모두 완료로',
onClick: () => {
api.updateRows(api.getRows().map((row) => ({ ...row, done: true })));
log({ ko: '모든 작업을 완료로 바꿨어요.', en: 'All tasks are marked done.' });
api.setHeaderRendererParams('done', params); // 속성을 다시 알려 머리글을 다시 그려요(disabled를 다시 평가)
},
// 이미 모두 완료이면 막아요. 값은 머리글을 그릴 때 평가돼요.
disabled: () => api.getRows().every((row) => row.done),
};
api.setColumns([
{ id: 'task', title: '작업', width: 170, sortable: true },
{ id: 'owner', title: '담당', width: 100, sortable: true },
{
id: 'done',
title: '완료',
kind: 'boolean',
width: 190,
sortable: false,
headerRenderer: 'button',
headerRendererParams: params,
},
]);
log({
ko: '"완료" 머리글의 버튼을 눌러 보세요. 한 번 누르면 버튼이 비활성이 돼요.',
en: 'Press the button in the Done header. After one press it becomes disabled.',
});
}
export const options: GridOptions<Row> = { columns: [{ id: 'task' }], rows, rowKey: 'id' };
export const actions = {
reset: (api: GridApi<Row>) => {
api.updateRows(api.getRows().map((row) => ({ ...row, done: false })));
api.updateColumn('done', {
headerRendererParams: api.getColumns().find((c) => c.id === 'done')?.headerRendererParams,
});
},
};버튼을 누르면 이 예제의 코드가 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.reset(api)"
>되돌리기</button>
</div>
<mx-grid style="height: 200px" [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;
task: string;
owner: string;
done: boolean;
}
const rows: Row[] = [
{ id: 1, task: '로그인 화면 수정', owner: '김하늘', done: false },
{ id: 2, task: '결제 흐름 검토', owner: '이도윤', done: true },
{ id: 3, task: '새 아이콘 세트', owner: '박서연', done: false },
{ id: 4, task: '배포 점검', owner: '최지우', done: false },
];
// headerRenderer: 'button'은 머리글 제목 옆에 버튼을 넣어요. 누르면 정렬·끌기·메뉴는 일어나지 않고 onClick만 불려요.
// 정렬이 꺼진 컬럼은 머리글에 포커스를 두고(Tab 대신 focusHeader) Enter·Space로도 눌러요.
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
const params = {
label: '모두 완료로',
onClick: () => {
api.updateRows(api.getRows().map((row) => ({ ...row, done: true })));
log({ ko: '모든 작업을 완료로 바꿨어요.', en: 'All tasks are marked done.' });
api.setHeaderRendererParams('done', params); // 속성을 다시 알려 머리글을 다시 그려요(disabled를 다시 평가)
},
// 이미 모두 완료이면 막아요. 값은 머리글을 그릴 때 평가돼요.
disabled: () => api.getRows().every((row) => row.done),
};
api.setColumns([
{ id: 'task', title: '작업', width: 170, sortable: true },
{ id: 'owner', title: '담당', width: 100, sortable: true },
{
id: 'done',
title: '완료',
kind: 'boolean',
width: 190,
sortable: false,
headerRenderer: 'button',
headerRendererParams: params,
},
]);
log({
ko: '"완료" 머리글의 버튼을 눌러 보세요. 한 번 누르면 버튼이 비활성이 돼요.',
en: 'Press the button in the Done header. After one press it becomes disabled.',
});
}
export const options: GridOptions<Row> = { columns: [{ id: 'task' }], rows, rowKey: 'id' };
export const actions = {
reset: (api: GridApi<Row>) => {
api.updateRows(api.getRows().map((row) => ({ ...row, done: false })));
api.updateColumn('done', {
headerRendererParams: api.getColumns().find((c) => c.id === 'done')?.headerRendererParams,
});
},
};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="reset">Reset</button>
</div>
<div id="grid" style="height: 200px"></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('reset').addEventListener('click', () => actions.reset(api));const rows = [
{ id: 1, task: 'Fix login screen', owner: 'Liam Carter', done: false },
{ id: 2, task: 'Review payment flow', owner: 'Ethan Clark', done: true },
{ id: 3, task: 'New icon set', owner: 'Emma Stone', done: false },
{ id: 4, task: 'Deployment check', owner: 'Olivia Reed', done: false },
];
// headerRenderer: 'button' puts a button next to the header title. Pressing it triggers no sort, drag or menu; only onClick is called.
// For a column with sorting off, put focus on the header (focusHeader instead of Tab) and press it with Enter or Space too.
export function setup(api, log) {
const params = {
label: 'Mark all done',
onClick: () => {
api.updateRows(api.getRows().map((row) => ({ ...row, done: true })));
log('All tasks are marked done.');
api.setHeaderRendererParams('done', params); // Report the params again so the header is redrawn (disabled is evaluated again)
},
// Disabled once everything is done. The value is evaluated when the header is drawn.
disabled: () => api.getRows().every((row) => row.done),
};
api.setColumns([
{ id: 'task', title: 'Task', width: 170, sortable: true },
{ id: 'owner', title: 'Owner', width: 100, sortable: true },
{
id: 'done',
title: 'Done',
kind: 'boolean',
width: 190,
sortable: false,
headerRenderer: 'button',
headerRendererParams: params,
},
]);
log('Press the button in the Done header. After one press it becomes disabled.');
}
export const options = { columns: [{ id: 'task' }], rows, rowKey: 'id' };
export const actions = {
reset: (api) => {
api.updateRows(api.getRows().map((row) => ({ ...row, done: false })));
api.updateColumn('done', {
headerRendererParams: api.getColumns().find((c) => c.id === 'done')?.headerRendererParams,
});
},
};<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Put a button in a header</title>
</head>
<body>
<div class="toolbar">
<button type="button" id="reset">Reset</button>
</div>
<div id="grid" style="height: 200px"></div>
<ul id="log" aria-live="polite"></ul>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script>
const rows = [
{ id: 1, task: 'Fix login screen', owner: 'Liam Carter', done: false },
{ id: 2, task: 'Review payment flow', owner: 'Ethan Clark', done: true },
{ id: 3, task: 'New icon set', owner: 'Emma Stone', done: false },
{ id: 4, task: 'Deployment check', owner: 'Olivia Reed', done: false },
];
// headerRenderer: 'button' puts a button next to the header title. Pressing it triggers no sort, drag or menu; only onClick is called.
// For a column with sorting off, put focus on the header (focusHeader instead of Tab) and press it with Enter or Space too.
function setup(api, log) {
const params = {
label: 'Mark all done',
onClick: () => {
api.updateRows(api.getRows().map((row) => ({ ...row, done: true })));
log('All tasks are marked done.');
api.setHeaderRendererParams('done', params); // Report the params again so the header is redrawn (disabled is evaluated again)
},
// Disabled once everything is done. The value is evaluated when the header is drawn.
disabled: () => api.getRows().every((row) => row.done),
};
api.setColumns([
{ id: 'task', title: 'Task', width: 170, sortable: true },
{ id: 'owner', title: 'Owner', width: 100, sortable: true },
{
id: 'done',
title: 'Done',
kind: 'boolean',
width: 190,
sortable: false,
headerRenderer: 'button',
headerRendererParams: params,
},
]);
log('Press the button in the Done header. After one press it becomes disabled.');
}
const options = { columns: [{ id: 'task' }], rows, rowKey: 'id' };
const actions = {
reset: (api) => {
api.updateRows(api.getRows().map((row) => ({ ...row, done: false })));
api.updateColumn('done', {
headerRendererParams: api.getColumns().find((c) => c.id === 'done')?.headerRendererParams,
});
},
};
options.ariaLabel = "Put a button in a header";
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('reset').addEventListener('click', () => actions.reset(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.reset(api)}
>Reset</button>
</div>
<Grid style={{ height: 200 }} ref={gridRef} options={options} />
</>
);
}import type { GridApi, GridOptions } from '@maxgrid/react';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
task: string;
owner: string;
done: boolean;
}
const rows: Row[] = [
{ id: 1, task: 'Fix login screen', owner: 'Liam Carter', done: false },
{ id: 2, task: 'Review payment flow', owner: 'Ethan Clark', done: true },
{ id: 3, task: 'New icon set', owner: 'Emma Stone', done: false },
{ id: 4, task: 'Deployment check', owner: 'Olivia Reed', done: false },
];
// headerRenderer: 'button' puts a button next to the header title. Pressing it triggers no sort, drag or menu; only onClick is called.
// For a column with sorting off, put focus on the header (focusHeader instead of Tab) and press it with Enter or Space too.
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
const params = {
label: 'Mark all done',
onClick: () => {
api.updateRows(api.getRows().map((row) => ({ ...row, done: true })));
log('All tasks are marked done.');
api.setHeaderRendererParams('done', params); // Report the params again so the header is redrawn (disabled is evaluated again)
},
// Disabled once everything is done. The value is evaluated when the header is drawn.
disabled: () => api.getRows().every((row) => row.done),
};
api.setColumns([
{ id: 'task', title: 'Task', width: 170, sortable: true },
{ id: 'owner', title: 'Owner', width: 100, sortable: true },
{
id: 'done',
title: 'Done',
kind: 'boolean',
width: 190,
sortable: false,
headerRenderer: 'button',
headerRendererParams: params,
},
]);
log('Press the button in the Done header. After one press it becomes disabled.');
}
export const options: GridOptions<Row> = { columns: [{ id: 'task' }], rows, rowKey: 'id' };
export const actions = {
reset: (api: GridApi<Row>) => {
api.updateRows(api.getRows().map((row) => ({ ...row, done: false })));
api.updateColumn('done', {
headerRendererParams: api.getColumns().find((c) => c.id === 'done')?.headerRendererParams,
});
},
};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.reset(api)">Reset</button>
</div>
<Grid style="height: 200px" :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;
task: string;
owner: string;
done: boolean;
}
const rows: Row[] = [
{ id: 1, task: 'Fix login screen', owner: 'Liam Carter', done: false },
{ id: 2, task: 'Review payment flow', owner: 'Ethan Clark', done: true },
{ id: 3, task: 'New icon set', owner: 'Emma Stone', done: false },
{ id: 4, task: 'Deployment check', owner: 'Olivia Reed', done: false },
];
// headerRenderer: 'button' puts a button next to the header title. Pressing it triggers no sort, drag or menu; only onClick is called.
// For a column with sorting off, put focus on the header (focusHeader instead of Tab) and press it with Enter or Space too.
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
const params = {
label: 'Mark all done',
onClick: () => {
api.updateRows(api.getRows().map((row) => ({ ...row, done: true })));
log('All tasks are marked done.');
api.setHeaderRendererParams('done', params); // Report the params again so the header is redrawn (disabled is evaluated again)
},
// Disabled once everything is done. The value is evaluated when the header is drawn.
disabled: () => api.getRows().every((row) => row.done),
};
api.setColumns([
{ id: 'task', title: 'Task', width: 170, sortable: true },
{ id: 'owner', title: 'Owner', width: 100, sortable: true },
{
id: 'done',
title: 'Done',
kind: 'boolean',
width: 190,
sortable: false,
headerRenderer: 'button',
headerRendererParams: params,
},
]);
log('Press the button in the Done header. After one press it becomes disabled.');
}
export const options: GridOptions<Row> = { columns: [{ id: 'task' }], rows, rowKey: 'id' };
export const actions = {
reset: (api: GridApi<Row>) => {
api.updateRows(api.getRows().map((row) => ({ ...row, done: false })));
api.updateColumn('done', {
headerRendererParams: api.getColumns().find((c) => c.id === 'done')?.headerRendererParams,
});
},
};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.reset(api)"
>Reset</button>
</div>
<mx-grid style="height: 200px" [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;
task: string;
owner: string;
done: boolean;
}
const rows: Row[] = [
{ id: 1, task: 'Fix login screen', owner: 'Liam Carter', done: false },
{ id: 2, task: 'Review payment flow', owner: 'Ethan Clark', done: true },
{ id: 3, task: 'New icon set', owner: 'Emma Stone', done: false },
{ id: 4, task: 'Deployment check', owner: 'Olivia Reed', done: false },
];
// headerRenderer: 'button' puts a button next to the header title. Pressing it triggers no sort, drag or menu; only onClick is called.
// For a column with sorting off, put focus on the header (focusHeader instead of Tab) and press it with Enter or Space too.
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
const params = {
label: 'Mark all done',
onClick: () => {
api.updateRows(api.getRows().map((row) => ({ ...row, done: true })));
log('All tasks are marked done.');
api.setHeaderRendererParams('done', params); // Report the params again so the header is redrawn (disabled is evaluated again)
},
// Disabled once everything is done. The value is evaluated when the header is drawn.
disabled: () => api.getRows().every((row) => row.done),
};
api.setColumns([
{ id: 'task', title: 'Task', width: 170, sortable: true },
{ id: 'owner', title: 'Owner', width: 100, sortable: true },
{
id: 'done',
title: 'Done',
kind: 'boolean',
width: 190,
sortable: false,
headerRenderer: 'button',
headerRendererParams: params,
},
]);
log('Press the button in the Done header. After one press it becomes disabled.');
}
export const options: GridOptions<Row> = { columns: [{ id: 'task' }], rows, rowKey: 'id' };
export const actions = {
reset: (api: GridApi<Row>) => {
api.updateRows(api.getRows().map((row) => ({ ...row, done: false })));
api.updateColumn('done', {
headerRendererParams: api.getColumns().find((c) => c.id === 'done')?.headerRendererParams,
});
},
};