버튼으로 숫자 올리고 내리기Raise and lower numbers with buttons
cellEditor 'stepper'는 숫자 칸에 올리기·내리기 버튼을 붙여요. step, min, max, repeat, layout, typing 옵션으로 걸음 크기, 범위, 누르고 있을 때의 반복, 버튼 모양, 직접 입력 여부를 정해요. 범위 밖 숫자를 직접 치면 고치지 않고 확정할 때 이유를 알려 줘요.cellEditor 'stepper' adds increase and decrease buttons to a number cell. The step, min, max, repeat, layout and typing options set the step size, the range, the repeat while held, the button layout and whether typing is allowed. A typed number outside the range is not corrected; the commit explains why it is refused.
코드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 id="grid" style="height: 280px"></div>
</div>
<script type="module" src="./main.js"></script>import { createGrid } from 'maxgrid';
import { options, setup } from './example';
const api = createGrid(document.getElementById('grid'), options);
setup(api, console.log);const rows = [
{ id: 1, item: '노트북 거치대', qty: 3, discount: 10, price: 24.5 },
{ id: 2, item: '무선 마우스', qty: 12, discount: 0, price: 18 },
{ id: 3, item: '모니터 암', qty: null, discount: 25, price: 52.9 },
{ id: 4, item: 'USB 허브', qty: 99, discount: 5, price: 12.3 },
];
// cellEditor: 'stepper'는 editors 묶음이 필요해요(전체 번들에는 들어 있어요).
// editorParams: step(걸음 크기), min·max(범위), repeat(누르고 있을 때 반복 ms), layout('sides' | 'stacked'),
// typing(false면 버튼과 키로만 바꿈), decimals(결과 소수 자릿수).
export const options = {
columns: [
{ id: 'item', title: '품목', width: 150 },
{
id: 'qty',
title: '수량',
kind: 'number',
width: 150,
editable: true,
cellEditor: 'stepper',
editorParams: { step: 1, min: 0, max: 99 },
},
{
id: 'discount',
title: '할인율(%)',
kind: 'number',
width: 140,
editable: true,
cellEditor: 'stepper',
editorParams: { step: 5, min: 0, max: 50, layout: 'stacked', typing: false },
},
{
id: 'price',
title: '단가',
kind: 'number',
width: 140,
editable: true,
cellEditor: 'stepper',
editorParams: { step: 0.1, min: 0, decimals: 1, repeat: 120 },
},
],
rows,
rowKey: 'id',
};
export function setup(api, log) {
log({
ko: '"수량"·"할인율"·"단가" 칸을 두 번 누르세요. − + 버튼이나 위아래 키로 바꿔요.',
en: 'Double-click a "수량" (qty), "할인율" (discount) or "단가" (price) cell. Change it with the − + buttons or the up and down keys.',
});
const offs = [
api.on('editCommitted', (e) => log({
ko: `행 ${e.rowKey}: ${e.columnId} = ${String(e.newValue)}`,
en: `Row ${e.rowKey}: ${e.columnId} = ${String(e.newValue)}`,
})),
api.on('validationFailed', (e) => log(e.message)),
];
return () => offs.forEach((off) => off());
}<!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 id="grid" style="height: 280px"></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, item: '노트북 거치대', qty: 3, discount: 10, price: 24.5 },
{ id: 2, item: '무선 마우스', qty: 12, discount: 0, price: 18 },
{ id: 3, item: '모니터 암', qty: null, discount: 25, price: 52.9 },
{ id: 4, item: 'USB 허브', qty: 99, discount: 5, price: 12.3 },
];
// cellEditor: 'stepper'는 editors 묶음이 필요해요(전체 번들에는 들어 있어요).
// editorParams: step(걸음 크기), min·max(범위), repeat(누르고 있을 때 반복 ms), layout('sides' | 'stacked'),
// typing(false면 버튼과 키로만 바꿈), decimals(결과 소수 자릿수).
const options = {
columns: [
{ id: 'item', title: '품목', width: 150 },
{
id: 'qty',
title: '수량',
kind: 'number',
width: 150,
editable: true,
cellEditor: 'stepper',
editorParams: { step: 1, min: 0, max: 99 },
},
{
id: 'discount',
title: '할인율(%)',
kind: 'number',
width: 140,
editable: true,
cellEditor: 'stepper',
editorParams: { step: 5, min: 0, max: 50, layout: 'stacked', typing: false },
},
{
id: 'price',
title: '단가',
kind: 'number',
width: 140,
editable: true,
cellEditor: 'stepper',
editorParams: { step: 0.1, min: 0, decimals: 1, repeat: 120 },
},
],
rows,
rowKey: 'id',
};
function setup(api, log) {
log({
ko: '"수량"·"할인율"·"단가" 칸을 두 번 누르세요. − + 버튼이나 위아래 키로 바꿔요.',
en: 'Double-click a "수량" (qty), "할인율" (discount) or "단가" (price) cell. Change it with the − + buttons or the up and down keys.',
});
const offs = [
api.on('editCommitted', (e) => log({
ko: `행 ${e.rowKey}: ${e.columnId} = ${String(e.newValue)}`,
en: `Row ${e.rowKey}: ${e.columnId} = ${String(e.newValue)}`,
})),
api.on('validationFailed', (e) => log(e.message)),
];
return () => offs.forEach((off) => off());
}
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);
});
</script>
</body>
</html>버튼을 누르면 이 예제의 코드가 StackBlitz나 CodeSandbox로 전송돼요. 누르기 전에는 아무것도 보내지 않아요.
import { useEffect } from 'react';
import { Grid, useGridApi } from '@maxgrid/react';
import { options, setup, type Row } from './example';
export function ExampleGrid() {
const [api, gridRef] = useGridApi<Row>();
useEffect(() => (api ? setup(api, console.log) : undefined), [api]);
return (
<>
<Grid style={{ height: 280 }} ref={gridRef} options={options} />
</>
);
}import type { GridApi, GridOptions } from '@maxgrid/react';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
item: string;
qty: number | null;
discount: number;
price: number;
}
const rows: Row[] = [
{ id: 1, item: '노트북 거치대', qty: 3, discount: 10, price: 24.5 },
{ id: 2, item: '무선 마우스', qty: 12, discount: 0, price: 18 },
{ id: 3, item: '모니터 암', qty: null, discount: 25, price: 52.9 },
{ id: 4, item: 'USB 허브', qty: 99, discount: 5, price: 12.3 },
];
// cellEditor: 'stepper'는 editors 묶음이 필요해요(전체 번들에는 들어 있어요).
// editorParams: step(걸음 크기), min·max(범위), repeat(누르고 있을 때 반복 ms), layout('sides' | 'stacked'),
// typing(false면 버튼과 키로만 바꿈), decimals(결과 소수 자릿수).
export const options: GridOptions<Row> = {
columns: [
{ id: 'item', title: '품목', width: 150 },
{
id: 'qty',
title: '수량',
kind: 'number',
width: 150,
editable: true,
cellEditor: 'stepper',
editorParams: { step: 1, min: 0, max: 99 },
},
{
id: 'discount',
title: '할인율(%)',
kind: 'number',
width: 140,
editable: true,
cellEditor: 'stepper',
editorParams: { step: 5, min: 0, max: 50, layout: 'stacked', typing: false },
},
{
id: 'price',
title: '단가',
kind: 'number',
width: 140,
editable: true,
cellEditor: 'stepper',
editorParams: { step: 0.1, min: 0, decimals: 1, repeat: 120 },
},
],
rows,
rowKey: 'id',
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
log({
ko: '"수량"·"할인율"·"단가" 칸을 두 번 누르세요. − + 버튼이나 위아래 키로 바꿔요.',
en: 'Double-click a "수량" (qty), "할인율" (discount) or "단가" (price) cell. Change it with the − + buttons or the up and down keys.',
});
const offs = [
api.on('editCommitted', (e) =>
log({
ko: `행 ${e.rowKey}: ${e.columnId} = ${String(e.newValue)}`,
en: `Row ${e.rowKey}: ${e.columnId} = ${String(e.newValue)}`,
}),
),
api.on('validationFailed', (e) => log(e.message)),
];
return () => offs.forEach((off) => off());
}버튼을 누르면 이 예제의 코드가 StackBlitz나 CodeSandbox로 전송돼요. 누르기 전에는 아무것도 보내지 않아요.
<script setup lang="ts">
import { onBeforeUnmount, shallowRef } from 'vue';
import { Grid, type GridApi } from '@maxgrid/vue';
import { 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>
<Grid style="height: 280px" :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;
item: string;
qty: number | null;
discount: number;
price: number;
}
const rows: Row[] = [
{ id: 1, item: '노트북 거치대', qty: 3, discount: 10, price: 24.5 },
{ id: 2, item: '무선 마우스', qty: 12, discount: 0, price: 18 },
{ id: 3, item: '모니터 암', qty: null, discount: 25, price: 52.9 },
{ id: 4, item: 'USB 허브', qty: 99, discount: 5, price: 12.3 },
];
// cellEditor: 'stepper'는 editors 묶음이 필요해요(전체 번들에는 들어 있어요).
// editorParams: step(걸음 크기), min·max(범위), repeat(누르고 있을 때 반복 ms), layout('sides' | 'stacked'),
// typing(false면 버튼과 키로만 바꿈), decimals(결과 소수 자릿수).
export const options: GridOptions<Row> = {
columns: [
{ id: 'item', title: '품목', width: 150 },
{
id: 'qty',
title: '수량',
kind: 'number',
width: 150,
editable: true,
cellEditor: 'stepper',
editorParams: { step: 1, min: 0, max: 99 },
},
{
id: 'discount',
title: '할인율(%)',
kind: 'number',
width: 140,
editable: true,
cellEditor: 'stepper',
editorParams: { step: 5, min: 0, max: 50, layout: 'stacked', typing: false },
},
{
id: 'price',
title: '단가',
kind: 'number',
width: 140,
editable: true,
cellEditor: 'stepper',
editorParams: { step: 0.1, min: 0, decimals: 1, repeat: 120 },
},
],
rows,
rowKey: 'id',
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
log({
ko: '"수량"·"할인율"·"단가" 칸을 두 번 누르세요. − + 버튼이나 위아래 키로 바꿔요.',
en: 'Double-click a "수량" (qty), "할인율" (discount) or "단가" (price) cell. Change it with the − + buttons or the up and down keys.',
});
const offs = [
api.on('editCommitted', (e) =>
log({
ko: `행 ${e.rowKey}: ${e.columnId} = ${String(e.newValue)}`,
en: `Row ${e.rowKey}: ${e.columnId} = ${String(e.newValue)}`,
}),
),
api.on('validationFailed', (e) => log(e.message)),
];
return () => offs.forEach((off) => off());
}버튼을 누르면 이 예제의 코드가 StackBlitz나 CodeSandbox로 전송돼요. 누르기 전에는 아무것도 보내지 않아요.
import { Component, OnDestroy } from '@angular/core';
import { GridComponent, isGridEvent, type GridApi, type GridEventMessage } from '@maxgrid/angular';
import { options, setup, type Row } from './example';
@Component({
selector: 'app-example-grid',
standalone: true,
imports: [GridComponent],
template: `
<mx-grid style="height: 280px" [options]="options" [events]="relayed" (gridEvent)="onEvent($event)" />
`,
})
export class ExampleGridComponent implements OnDestroy {
readonly options = options;
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;
item: string;
qty: number | null;
discount: number;
price: number;
}
const rows: Row[] = [
{ id: 1, item: '노트북 거치대', qty: 3, discount: 10, price: 24.5 },
{ id: 2, item: '무선 마우스', qty: 12, discount: 0, price: 18 },
{ id: 3, item: '모니터 암', qty: null, discount: 25, price: 52.9 },
{ id: 4, item: 'USB 허브', qty: 99, discount: 5, price: 12.3 },
];
// cellEditor: 'stepper'는 editors 묶음이 필요해요(전체 번들에는 들어 있어요).
// editorParams: step(걸음 크기), min·max(범위), repeat(누르고 있을 때 반복 ms), layout('sides' | 'stacked'),
// typing(false면 버튼과 키로만 바꿈), decimals(결과 소수 자릿수).
export const options: GridOptions<Row> = {
columns: [
{ id: 'item', title: '품목', width: 150 },
{
id: 'qty',
title: '수량',
kind: 'number',
width: 150,
editable: true,
cellEditor: 'stepper',
editorParams: { step: 1, min: 0, max: 99 },
},
{
id: 'discount',
title: '할인율(%)',
kind: 'number',
width: 140,
editable: true,
cellEditor: 'stepper',
editorParams: { step: 5, min: 0, max: 50, layout: 'stacked', typing: false },
},
{
id: 'price',
title: '단가',
kind: 'number',
width: 140,
editable: true,
cellEditor: 'stepper',
editorParams: { step: 0.1, min: 0, decimals: 1, repeat: 120 },
},
],
rows,
rowKey: 'id',
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
log({
ko: '"수량"·"할인율"·"단가" 칸을 두 번 누르세요. − + 버튼이나 위아래 키로 바꿔요.',
en: 'Double-click a "수량" (qty), "할인율" (discount) or "단가" (price) cell. Change it with the − + buttons or the up and down keys.',
});
const offs = [
api.on('editCommitted', (e) =>
log({
ko: `행 ${e.rowKey}: ${e.columnId} = ${String(e.newValue)}`,
en: `Row ${e.rowKey}: ${e.columnId} = ${String(e.newValue)}`,
}),
),
api.on('validationFailed', (e) => log(e.message)),
];
return () => offs.forEach((off) => off());
}When you click, the example code is sent to StackBlitz or CodeSandbox. Nothing is sent before you click.
<div id="app">
<div id="grid" style="height: 280px"></div>
</div>
<script type="module" src="./main.js"></script>import { createGrid } from 'maxgrid';
import { options, setup } from './example';
const api = createGrid(document.getElementById('grid'), options);
setup(api, console.log);const rows = [
{ id: 1, item: 'Laptop stand', qty: 3, discount: 10, price: 24.5 },
{ id: 2, item: 'Wireless mouse', qty: 12, discount: 0, price: 18 },
{ id: 3, item: 'Monitor arm', qty: null, discount: 25, price: 52.9 },
{ id: 4, item: 'USB hub', qty: 99, discount: 5, price: 12.3 },
];
// cellEditor: 'stepper' needs the editors bundle (the full bundle includes it).
// editorParams: step (step size), min and max (range), repeat (repeat interval in ms while held), layout ('sides' | 'stacked'),
// typing (false changes only with buttons and keys), decimals (decimal places of the result).
export const options = {
columns: [
{ id: 'item', title: 'Item', width: 150 },
{
id: 'qty',
title: 'Qty',
kind: 'number',
width: 150,
editable: true,
cellEditor: 'stepper',
editorParams: { step: 1, min: 0, max: 99 },
},
{
id: 'discount',
title: 'Discount (%)',
kind: 'number',
width: 140,
editable: true,
cellEditor: 'stepper',
editorParams: { step: 5, min: 0, max: 50, layout: 'stacked', typing: false },
},
{
id: 'price',
title: 'Unit price',
kind: 'number',
width: 140,
editable: true,
cellEditor: 'stepper',
editorParams: { step: 0.1, min: 0, decimals: 1, repeat: 120 },
},
],
rows,
rowKey: 'id',
};
export function setup(api, log) {
log('Double-click a "Qty", "Discount" or "Unit price" cell. Change it with the − + buttons or the up and down keys.');
const offs = [
api.on('editCommitted', (e) => log(`Row ${e.rowKey}: ${e.columnId} = ${String(e.newValue)}`)),
api.on('validationFailed', (e) => log(e.message)),
];
return () => offs.forEach((off) => off());
}<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Raise and lower numbers with buttons</title>
</head>
<body>
<div id="grid" style="height: 280px"></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, item: 'Laptop stand', qty: 3, discount: 10, price: 24.5 },
{ id: 2, item: 'Wireless mouse', qty: 12, discount: 0, price: 18 },
{ id: 3, item: 'Monitor arm', qty: null, discount: 25, price: 52.9 },
{ id: 4, item: 'USB hub', qty: 99, discount: 5, price: 12.3 },
];
// cellEditor: 'stepper' needs the editors bundle (the full bundle includes it).
// editorParams: step (step size), min and max (range), repeat (repeat interval in ms while held), layout ('sides' | 'stacked'),
// typing (false changes only with buttons and keys), decimals (decimal places of the result).
const options = {
columns: [
{ id: 'item', title: 'Item', width: 150 },
{
id: 'qty',
title: 'Qty',
kind: 'number',
width: 150,
editable: true,
cellEditor: 'stepper',
editorParams: { step: 1, min: 0, max: 99 },
},
{
id: 'discount',
title: 'Discount (%)',
kind: 'number',
width: 140,
editable: true,
cellEditor: 'stepper',
editorParams: { step: 5, min: 0, max: 50, layout: 'stacked', typing: false },
},
{
id: 'price',
title: 'Unit price',
kind: 'number',
width: 140,
editable: true,
cellEditor: 'stepper',
editorParams: { step: 0.1, min: 0, decimals: 1, repeat: 120 },
},
],
rows,
rowKey: 'id',
};
function setup(api, log) {
log('Double-click a "Qty", "Discount" or "Unit price" cell. Change it with the − + buttons or the up and down keys.');
const offs = [
api.on('editCommitted', (e) => log(`Row ${e.rowKey}: ${e.columnId} = ${String(e.newValue)}`)),
api.on('validationFailed', (e) => log(e.message)),
];
return () => offs.forEach((off) => off());
}
options.ariaLabel = "Raise and lower numbers with buttons";
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);
});
</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 { options, setup, type Row } from './example';
export function ExampleGrid() {
const [api, gridRef] = useGridApi<Row>();
useEffect(() => (api ? setup(api, console.log) : undefined), [api]);
return (
<>
<Grid style={{ height: 280 }} ref={gridRef} options={options} />
</>
);
}import type { GridApi, GridOptions } from '@maxgrid/react';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
item: string;
qty: number | null;
discount: number;
price: number;
}
const rows: Row[] = [
{ id: 1, item: 'Laptop stand', qty: 3, discount: 10, price: 24.5 },
{ id: 2, item: 'Wireless mouse', qty: 12, discount: 0, price: 18 },
{ id: 3, item: 'Monitor arm', qty: null, discount: 25, price: 52.9 },
{ id: 4, item: 'USB hub', qty: 99, discount: 5, price: 12.3 },
];
// cellEditor: 'stepper' needs the editors bundle (the full bundle includes it).
// editorParams: step (step size), min and max (range), repeat (repeat interval in ms while held), layout ('sides' | 'stacked'),
// typing (false changes only with buttons and keys), decimals (decimal places of the result).
export const options: GridOptions<Row> = {
columns: [
{ id: 'item', title: 'Item', width: 150 },
{
id: 'qty',
title: 'Qty',
kind: 'number',
width: 150,
editable: true,
cellEditor: 'stepper',
editorParams: { step: 1, min: 0, max: 99 },
},
{
id: 'discount',
title: 'Discount (%)',
kind: 'number',
width: 140,
editable: true,
cellEditor: 'stepper',
editorParams: { step: 5, min: 0, max: 50, layout: 'stacked', typing: false },
},
{
id: 'price',
title: 'Unit price',
kind: 'number',
width: 140,
editable: true,
cellEditor: 'stepper',
editorParams: { step: 0.1, min: 0, decimals: 1, repeat: 120 },
},
],
rows,
rowKey: 'id',
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
log(
'Double-click a "Qty", "Discount" or "Unit price" cell. Change it with the − + buttons or the up and down keys.',
);
const offs = [
api.on('editCommitted', (e) => log(`Row ${e.rowKey}: ${e.columnId} = ${String(e.newValue)}`)),
api.on('validationFailed', (e) => log(e.message)),
];
return () => offs.forEach((off) => off());
}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 { 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>
<Grid style="height: 280px" :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;
item: string;
qty: number | null;
discount: number;
price: number;
}
const rows: Row[] = [
{ id: 1, item: 'Laptop stand', qty: 3, discount: 10, price: 24.5 },
{ id: 2, item: 'Wireless mouse', qty: 12, discount: 0, price: 18 },
{ id: 3, item: 'Monitor arm', qty: null, discount: 25, price: 52.9 },
{ id: 4, item: 'USB hub', qty: 99, discount: 5, price: 12.3 },
];
// cellEditor: 'stepper' needs the editors bundle (the full bundle includes it).
// editorParams: step (step size), min and max (range), repeat (repeat interval in ms while held), layout ('sides' | 'stacked'),
// typing (false changes only with buttons and keys), decimals (decimal places of the result).
export const options: GridOptions<Row> = {
columns: [
{ id: 'item', title: 'Item', width: 150 },
{
id: 'qty',
title: 'Qty',
kind: 'number',
width: 150,
editable: true,
cellEditor: 'stepper',
editorParams: { step: 1, min: 0, max: 99 },
},
{
id: 'discount',
title: 'Discount (%)',
kind: 'number',
width: 140,
editable: true,
cellEditor: 'stepper',
editorParams: { step: 5, min: 0, max: 50, layout: 'stacked', typing: false },
},
{
id: 'price',
title: 'Unit price',
kind: 'number',
width: 140,
editable: true,
cellEditor: 'stepper',
editorParams: { step: 0.1, min: 0, decimals: 1, repeat: 120 },
},
],
rows,
rowKey: 'id',
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
log(
'Double-click a "Qty", "Discount" or "Unit price" cell. Change it with the − + buttons or the up and down keys.',
);
const offs = [
api.on('editCommitted', (e) => log(`Row ${e.rowKey}: ${e.columnId} = ${String(e.newValue)}`)),
api.on('validationFailed', (e) => log(e.message)),
];
return () => offs.forEach((off) => off());
}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 { options, setup, type Row } from './example';
@Component({
selector: 'app-example-grid',
standalone: true,
imports: [GridComponent],
template: `
<mx-grid style="height: 280px" [options]="options" [events]="relayed" (gridEvent)="onEvent($event)" />
`,
})
export class ExampleGridComponent implements OnDestroy {
readonly options = options;
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;
item: string;
qty: number | null;
discount: number;
price: number;
}
const rows: Row[] = [
{ id: 1, item: 'Laptop stand', qty: 3, discount: 10, price: 24.5 },
{ id: 2, item: 'Wireless mouse', qty: 12, discount: 0, price: 18 },
{ id: 3, item: 'Monitor arm', qty: null, discount: 25, price: 52.9 },
{ id: 4, item: 'USB hub', qty: 99, discount: 5, price: 12.3 },
];
// cellEditor: 'stepper' needs the editors bundle (the full bundle includes it).
// editorParams: step (step size), min and max (range), repeat (repeat interval in ms while held), layout ('sides' | 'stacked'),
// typing (false changes only with buttons and keys), decimals (decimal places of the result).
export const options: GridOptions<Row> = {
columns: [
{ id: 'item', title: 'Item', width: 150 },
{
id: 'qty',
title: 'Qty',
kind: 'number',
width: 150,
editable: true,
cellEditor: 'stepper',
editorParams: { step: 1, min: 0, max: 99 },
},
{
id: 'discount',
title: 'Discount (%)',
kind: 'number',
width: 140,
editable: true,
cellEditor: 'stepper',
editorParams: { step: 5, min: 0, max: 50, layout: 'stacked', typing: false },
},
{
id: 'price',
title: 'Unit price',
kind: 'number',
width: 140,
editable: true,
cellEditor: 'stepper',
editorParams: { step: 0.1, min: 0, decimals: 1, repeat: 120 },
},
],
rows,
rowKey: 'id',
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
log(
'Double-click a "Qty", "Discount" or "Unit price" cell. Change it with the − + buttons or the up and down keys.',
);
const offs = [
api.on('editCommitted', (e) => log(`Row ${e.rowKey}: ${e.columnId} = ${String(e.newValue)}`)),
api.on('validationFailed', (e) => log(e.message)),
];
return () => offs.forEach((off) => off());
}