색 칸 편집: 견본과 16진 입력Edit colors: swatches and hex input
cellEditor: 'color'는 견본 16개와 16진 입력칸을 열어요. 값은 소문자 #rrggbb이고, alpha를 켜면 #rrggbbaa예요. 칸에는 작은 견본과 글자가 보여요.cellEditor: 'color' opens 16 swatches and a hex input. The value is a lowercase #rrggbb, or #rrggbbaa with alpha. The cell shows a small swatch and the text.
코드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="editColor">색 편집</button>
</div>
<div id="grid" style="height: 300px"></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('editColor').addEventListener('click', () => actions.editColor(api));const en = document.documentElement.dataset.lang === 'en';
const rows = [
{ id: 1, label: en ? 'Default' : '기본 색', color: '#1a73e8', tint: '#1a73e8cc' },
{ id: 2, label: en ? 'Warning' : '경고', color: '#f9ab00', tint: '#f9ab0066' },
{ id: 3, label: en ? 'Danger' : '위험', color: '#d93025', tint: '#d9302533' },
{ id: 4, label: en ? 'Undecided' : '미정', color: null, tint: '#5f6368ff' },
];
// cellEditor: 'color'는 견본 격자와 16진 입력칸이 열려요. 값은 소문자 #rrggbb이고 alpha를 켜면 #rrggbbaa예요.
export const options = {
columns: [
{ id: 'label', title: en ? 'Name' : '이름', width: 130 },
{ id: 'color', title: en ? 'Color' : '색', width: 150, editable: true, cellEditor: 'color' },
{
id: 'tint',
title: en ? 'Color with alpha' : '투명도 있는 색',
width: 190,
editable: true,
cellEditor: 'color',
editorParams: {
alpha: true,
swatches: [
'#1a73e8',
'#188038',
'#f9ab00',
'#d93025',
'#9334e6',
'#5f6368',
'#1a73e8cc',
'#d9302533',
],
},
},
],
rows,
rowKey: 'id',
ariaLabel: en ? 'Edit colors' : '색 편집',
};
export function setup(api, log) {
log({
ko: '색 칸을 더블클릭하세요. 방향키로 견본을 옮기고 Enter로 고르거나, #1a73e8처럼 직접 써요. 형식이 틀리면 열린 채로 알려요.',
en: 'Double-click a color cell. Move over swatches with the arrows and press Enter, or type #1a73e8. A wrong format keeps the editor open with a message.',
});
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({ ko: `확정하지 못했어요: ${e.message}`, en: `Could not confirm: ${e.message}` })),
];
return () => offs.forEach((off) => off());
}
export const actions = {
editColor: (api) => api.startEdit(1, 'color'),
};<!doctype html>
<html lang="ko">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>색 칸 편집: 견본과 16진 입력</title>
</head>
<body>
<div class="toolbar">
<button type="button" id="editColor">색 편집</button>
</div>
<div id="grid" style="height: 300px"></div>
<ul id="log" aria-live="polite"></ul>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script>
const en = document.documentElement.dataset.lang === 'en';
const rows = [
{ id: 1, label: en ? 'Default' : '기본 색', color: '#1a73e8', tint: '#1a73e8cc' },
{ id: 2, label: en ? 'Warning' : '경고', color: '#f9ab00', tint: '#f9ab0066' },
{ id: 3, label: en ? 'Danger' : '위험', color: '#d93025', tint: '#d9302533' },
{ id: 4, label: en ? 'Undecided' : '미정', color: null, tint: '#5f6368ff' },
];
// cellEditor: 'color'는 견본 격자와 16진 입력칸이 열려요. 값은 소문자 #rrggbb이고 alpha를 켜면 #rrggbbaa예요.
const options = {
columns: [
{ id: 'label', title: en ? 'Name' : '이름', width: 130 },
{ id: 'color', title: en ? 'Color' : '색', width: 150, editable: true, cellEditor: 'color' },
{
id: 'tint',
title: en ? 'Color with alpha' : '투명도 있는 색',
width: 190,
editable: true,
cellEditor: 'color',
editorParams: {
alpha: true,
swatches: [
'#1a73e8',
'#188038',
'#f9ab00',
'#d93025',
'#9334e6',
'#5f6368',
'#1a73e8cc',
'#d9302533',
],
},
},
],
rows,
rowKey: 'id',
ariaLabel: en ? 'Edit colors' : '색 편집',
};
function setup(api, log) {
log({
ko: '색 칸을 더블클릭하세요. 방향키로 견본을 옮기고 Enter로 고르거나, #1a73e8처럼 직접 써요. 형식이 틀리면 열린 채로 알려요.',
en: 'Double-click a color cell. Move over swatches with the arrows and press Enter, or type #1a73e8. A wrong format keeps the editor open with a message.',
});
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({ ko: `확정하지 못했어요: ${e.message}`, en: `Could not confirm: ${e.message}` })),
];
return () => offs.forEach((off) => off());
}
const actions = {
editColor: (api) => api.startEdit(1, 'color'),
};
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('editColor').addEventListener('click', () => actions.editColor(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.editColor(api)}
>색 편집</button>
</div>
<Grid style={{ height: 300 }} ref={gridRef} options={options} />
</>
);
}import type { GridApi, GridOptions } from '@maxgrid/react';
const en = document.documentElement.dataset.lang === 'en';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
label: string;
color: string | null;
tint: string;
}
const rows: Row[] = [
{ id: 1, label: en ? 'Default' : '기본 색', color: '#1a73e8', tint: '#1a73e8cc' },
{ id: 2, label: en ? 'Warning' : '경고', color: '#f9ab00', tint: '#f9ab0066' },
{ id: 3, label: en ? 'Danger' : '위험', color: '#d93025', tint: '#d9302533' },
{ id: 4, label: en ? 'Undecided' : '미정', color: null, tint: '#5f6368ff' },
];
// cellEditor: 'color'는 견본 격자와 16진 입력칸이 열려요. 값은 소문자 #rrggbb이고 alpha를 켜면 #rrggbbaa예요.
export const options: GridOptions<Row> = {
columns: [
{ id: 'label', title: en ? 'Name' : '이름', width: 130 },
{ id: 'color', title: en ? 'Color' : '색', width: 150, editable: true, cellEditor: 'color' },
{
id: 'tint',
title: en ? 'Color with alpha' : '투명도 있는 색',
width: 190,
editable: true,
cellEditor: 'color',
editorParams: {
alpha: true,
swatches: [
'#1a73e8',
'#188038',
'#f9ab00',
'#d93025',
'#9334e6',
'#5f6368',
'#1a73e8cc',
'#d9302533',
],
},
},
],
rows,
rowKey: 'id',
ariaLabel: en ? 'Edit colors' : '색 편집',
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
log({
ko: '색 칸을 더블클릭하세요. 방향키로 견본을 옮기고 Enter로 고르거나, #1a73e8처럼 직접 써요. 형식이 틀리면 열린 채로 알려요.',
en: 'Double-click a color cell. Move over swatches with the arrows and press Enter, or type #1a73e8. A wrong format keeps the editor open with a message.',
});
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({ ko: `확정하지 못했어요: ${e.message}`, en: `Could not confirm: ${e.message}` }),
),
];
return () => offs.forEach((off) => off());
}
export const actions = {
editColor: (api: GridApi<Row>) => api.startEdit(1, 'color'),
};버튼을 누르면 이 예제의 코드가 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.editColor(api)"
>색 편집</button>
</div>
<Grid style="height: 300px" :options="options" @ready="onReady" />
</template>import type { GridApi, GridOptions } from '@maxgrid/vue';
const en = document.documentElement.dataset.lang === 'en';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
label: string;
color: string | null;
tint: string;
}
const rows: Row[] = [
{ id: 1, label: en ? 'Default' : '기본 색', color: '#1a73e8', tint: '#1a73e8cc' },
{ id: 2, label: en ? 'Warning' : '경고', color: '#f9ab00', tint: '#f9ab0066' },
{ id: 3, label: en ? 'Danger' : '위험', color: '#d93025', tint: '#d9302533' },
{ id: 4, label: en ? 'Undecided' : '미정', color: null, tint: '#5f6368ff' },
];
// cellEditor: 'color'는 견본 격자와 16진 입력칸이 열려요. 값은 소문자 #rrggbb이고 alpha를 켜면 #rrggbbaa예요.
export const options: GridOptions<Row> = {
columns: [
{ id: 'label', title: en ? 'Name' : '이름', width: 130 },
{ id: 'color', title: en ? 'Color' : '색', width: 150, editable: true, cellEditor: 'color' },
{
id: 'tint',
title: en ? 'Color with alpha' : '투명도 있는 색',
width: 190,
editable: true,
cellEditor: 'color',
editorParams: {
alpha: true,
swatches: [
'#1a73e8',
'#188038',
'#f9ab00',
'#d93025',
'#9334e6',
'#5f6368',
'#1a73e8cc',
'#d9302533',
],
},
},
],
rows,
rowKey: 'id',
ariaLabel: en ? 'Edit colors' : '색 편집',
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
log({
ko: '색 칸을 더블클릭하세요. 방향키로 견본을 옮기고 Enter로 고르거나, #1a73e8처럼 직접 써요. 형식이 틀리면 열린 채로 알려요.',
en: 'Double-click a color cell. Move over swatches with the arrows and press Enter, or type #1a73e8. A wrong format keeps the editor open with a message.',
});
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({ ko: `확정하지 못했어요: ${e.message}`, en: `Could not confirm: ${e.message}` }),
),
];
return () => offs.forEach((off) => off());
}
export const actions = {
editColor: (api: GridApi<Row>) => api.startEdit(1, 'color'),
};버튼을 누르면 이 예제의 코드가 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.editColor(api)"
>색 편집</button>
</div>
<mx-grid style="height: 300px" [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';
const en = document.documentElement.dataset.lang === 'en';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
label: string;
color: string | null;
tint: string;
}
const rows: Row[] = [
{ id: 1, label: en ? 'Default' : '기본 색', color: '#1a73e8', tint: '#1a73e8cc' },
{ id: 2, label: en ? 'Warning' : '경고', color: '#f9ab00', tint: '#f9ab0066' },
{ id: 3, label: en ? 'Danger' : '위험', color: '#d93025', tint: '#d9302533' },
{ id: 4, label: en ? 'Undecided' : '미정', color: null, tint: '#5f6368ff' },
];
// cellEditor: 'color'는 견본 격자와 16진 입력칸이 열려요. 값은 소문자 #rrggbb이고 alpha를 켜면 #rrggbbaa예요.
export const options: GridOptions<Row> = {
columns: [
{ id: 'label', title: en ? 'Name' : '이름', width: 130 },
{ id: 'color', title: en ? 'Color' : '색', width: 150, editable: true, cellEditor: 'color' },
{
id: 'tint',
title: en ? 'Color with alpha' : '투명도 있는 색',
width: 190,
editable: true,
cellEditor: 'color',
editorParams: {
alpha: true,
swatches: [
'#1a73e8',
'#188038',
'#f9ab00',
'#d93025',
'#9334e6',
'#5f6368',
'#1a73e8cc',
'#d9302533',
],
},
},
],
rows,
rowKey: 'id',
ariaLabel: en ? 'Edit colors' : '색 편집',
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
log({
ko: '색 칸을 더블클릭하세요. 방향키로 견본을 옮기고 Enter로 고르거나, #1a73e8처럼 직접 써요. 형식이 틀리면 열린 채로 알려요.',
en: 'Double-click a color cell. Move over swatches with the arrows and press Enter, or type #1a73e8. A wrong format keeps the editor open with a message.',
});
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({ ko: `확정하지 못했어요: ${e.message}`, en: `Could not confirm: ${e.message}` }),
),
];
return () => offs.forEach((off) => off());
}
export const actions = {
editColor: (api: GridApi<Row>) => api.startEdit(1, 'color'),
};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="editColor">Edit color</button>
</div>
<div id="grid" style="height: 300px"></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('editColor').addEventListener('click', () => actions.editColor(api));const rows = [
{ id: 1, label: 'Default', color: '#1a73e8', tint: '#1a73e8cc' },
{ id: 2, label: 'Warning', color: '#f9ab00', tint: '#f9ab0066' },
{ id: 3, label: 'Danger', color: '#d93025', tint: '#d9302533' },
{ id: 4, label: 'Undecided', color: null, tint: '#5f6368ff' },
];
// cellEditor: 'color' opens a swatch grid and a hex input. The value is a lowercase #rrggbb, or #rrggbbaa with alpha on.
export const options = {
columns: [
{ id: 'label', title: 'Name', width: 130 },
{ id: 'color', title: 'Color', width: 150, editable: true, cellEditor: 'color' },
{
id: 'tint',
title: 'Color with alpha',
width: 190,
editable: true,
cellEditor: 'color',
editorParams: {
alpha: true,
swatches: [
'#1a73e8',
'#188038',
'#f9ab00',
'#d93025',
'#9334e6',
'#5f6368',
'#1a73e8cc',
'#d9302533',
],
},
},
],
rows,
rowKey: 'id',
ariaLabel: 'Edit colors',
};
export function setup(api, log) {
log('Double-click a color cell. Move over swatches with the arrows and press Enter, or type #1a73e8. A wrong format keeps the editor open with a message.');
const offs = [
api.on('editCommitted', (e) => log(`Row ${e.rowKey} ${e.columnId} → ${String(e.newValue)}`)),
api.on('validationFailed', (e) => log(`Could not confirm: ${e.message}`)),
];
return () => offs.forEach((off) => off());
}
export const actions = {
editColor: (api) => api.startEdit(1, 'color'),
};<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Edit colors: swatches and hex input</title>
</head>
<body>
<div class="toolbar">
<button type="button" id="editColor">Edit color</button>
</div>
<div id="grid" style="height: 300px"></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, label: 'Default', color: '#1a73e8', tint: '#1a73e8cc' },
{ id: 2, label: 'Warning', color: '#f9ab00', tint: '#f9ab0066' },
{ id: 3, label: 'Danger', color: '#d93025', tint: '#d9302533' },
{ id: 4, label: 'Undecided', color: null, tint: '#5f6368ff' },
];
// cellEditor: 'color' opens a swatch grid and a hex input. The value is a lowercase #rrggbb, or #rrggbbaa with alpha on.
const options = {
columns: [
{ id: 'label', title: 'Name', width: 130 },
{ id: 'color', title: 'Color', width: 150, editable: true, cellEditor: 'color' },
{
id: 'tint',
title: 'Color with alpha',
width: 190,
editable: true,
cellEditor: 'color',
editorParams: {
alpha: true,
swatches: [
'#1a73e8',
'#188038',
'#f9ab00',
'#d93025',
'#9334e6',
'#5f6368',
'#1a73e8cc',
'#d9302533',
],
},
},
],
rows,
rowKey: 'id',
ariaLabel: 'Edit colors',
};
function setup(api, log) {
log('Double-click a color cell. Move over swatches with the arrows and press Enter, or type #1a73e8. A wrong format keeps the editor open with a message.');
const offs = [
api.on('editCommitted', (e) => log(`Row ${e.rowKey} ${e.columnId} → ${String(e.newValue)}`)),
api.on('validationFailed', (e) => log(`Could not confirm: ${e.message}`)),
];
return () => offs.forEach((off) => off());
}
const actions = {
editColor: (api) => api.startEdit(1, 'color'),
};
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('editColor').addEventListener('click', () => actions.editColor(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.editColor(api)}
>Edit color</button>
</div>
<Grid style={{ height: 300 }} ref={gridRef} options={options} />
</>
);
}import type { GridApi, GridOptions } from '@maxgrid/react';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
label: string;
color: string | null;
tint: string;
}
const rows: Row[] = [
{ id: 1, label: 'Default', color: '#1a73e8', tint: '#1a73e8cc' },
{ id: 2, label: 'Warning', color: '#f9ab00', tint: '#f9ab0066' },
{ id: 3, label: 'Danger', color: '#d93025', tint: '#d9302533' },
{ id: 4, label: 'Undecided', color: null, tint: '#5f6368ff' },
];
// cellEditor: 'color' opens a swatch grid and a hex input. The value is a lowercase #rrggbb, or #rrggbbaa with alpha on.
export const options: GridOptions<Row> = {
columns: [
{ id: 'label', title: 'Name', width: 130 },
{ id: 'color', title: 'Color', width: 150, editable: true, cellEditor: 'color' },
{
id: 'tint',
title: 'Color with alpha',
width: 190,
editable: true,
cellEditor: 'color',
editorParams: {
alpha: true,
swatches: [
'#1a73e8',
'#188038',
'#f9ab00',
'#d93025',
'#9334e6',
'#5f6368',
'#1a73e8cc',
'#d9302533',
],
},
},
],
rows,
rowKey: 'id',
ariaLabel: 'Edit colors',
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
log(
'Double-click a color cell. Move over swatches with the arrows and press Enter, or type #1a73e8. A wrong format keeps the editor open with a message.',
);
const offs = [
api.on('editCommitted', (e) => log(`Row ${e.rowKey} ${e.columnId} → ${String(e.newValue)}`)),
api.on('validationFailed', (e) => log(`Could not confirm: ${e.message}`)),
];
return () => offs.forEach((off) => off());
}
export const actions = {
editColor: (api: GridApi<Row>) => api.startEdit(1, 'color'),
};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.editColor(api)"
>Edit color</button>
</div>
<Grid style="height: 300px" :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;
label: string;
color: string | null;
tint: string;
}
const rows: Row[] = [
{ id: 1, label: 'Default', color: '#1a73e8', tint: '#1a73e8cc' },
{ id: 2, label: 'Warning', color: '#f9ab00', tint: '#f9ab0066' },
{ id: 3, label: 'Danger', color: '#d93025', tint: '#d9302533' },
{ id: 4, label: 'Undecided', color: null, tint: '#5f6368ff' },
];
// cellEditor: 'color' opens a swatch grid and a hex input. The value is a lowercase #rrggbb, or #rrggbbaa with alpha on.
export const options: GridOptions<Row> = {
columns: [
{ id: 'label', title: 'Name', width: 130 },
{ id: 'color', title: 'Color', width: 150, editable: true, cellEditor: 'color' },
{
id: 'tint',
title: 'Color with alpha',
width: 190,
editable: true,
cellEditor: 'color',
editorParams: {
alpha: true,
swatches: [
'#1a73e8',
'#188038',
'#f9ab00',
'#d93025',
'#9334e6',
'#5f6368',
'#1a73e8cc',
'#d9302533',
],
},
},
],
rows,
rowKey: 'id',
ariaLabel: 'Edit colors',
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
log(
'Double-click a color cell. Move over swatches with the arrows and press Enter, or type #1a73e8. A wrong format keeps the editor open with a message.',
);
const offs = [
api.on('editCommitted', (e) => log(`Row ${e.rowKey} ${e.columnId} → ${String(e.newValue)}`)),
api.on('validationFailed', (e) => log(`Could not confirm: ${e.message}`)),
];
return () => offs.forEach((off) => off());
}
export const actions = {
editColor: (api: GridApi<Row>) => api.startEdit(1, 'color'),
};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.editColor(api)"
>Edit color</button>
</div>
<mx-grid style="height: 300px" [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;
label: string;
color: string | null;
tint: string;
}
const rows: Row[] = [
{ id: 1, label: 'Default', color: '#1a73e8', tint: '#1a73e8cc' },
{ id: 2, label: 'Warning', color: '#f9ab00', tint: '#f9ab0066' },
{ id: 3, label: 'Danger', color: '#d93025', tint: '#d9302533' },
{ id: 4, label: 'Undecided', color: null, tint: '#5f6368ff' },
];
// cellEditor: 'color' opens a swatch grid and a hex input. The value is a lowercase #rrggbb, or #rrggbbaa with alpha on.
export const options: GridOptions<Row> = {
columns: [
{ id: 'label', title: 'Name', width: 130 },
{ id: 'color', title: 'Color', width: 150, editable: true, cellEditor: 'color' },
{
id: 'tint',
title: 'Color with alpha',
width: 190,
editable: true,
cellEditor: 'color',
editorParams: {
alpha: true,
swatches: [
'#1a73e8',
'#188038',
'#f9ab00',
'#d93025',
'#9334e6',
'#5f6368',
'#1a73e8cc',
'#d9302533',
],
},
},
],
rows,
rowKey: 'id',
ariaLabel: 'Edit colors',
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
log(
'Double-click a color cell. Move over swatches with the arrows and press Enter, or type #1a73e8. A wrong format keeps the editor open with a message.',
);
const offs = [
api.on('editCommitted', (e) => log(`Row ${e.rowKey} ${e.columnId} → ${String(e.newValue)}`)),
api.on('validationFailed', (e) => log(`Could not confirm: ${e.message}`)),
];
return () => offs.forEach((off) => off());
}
export const actions = {
editColor: (api: GridApi<Row>) => api.startEdit(1, 'color'),
};