업무 트리: 폴더 아이콘·가지선·상태 배지·진행 막대Task tree: folder icons, branch lines, status badges and progress bars
폴더 아이콘과 가지선으로 단계를 보여 주고, 다른 컬럼에는 상태 배지와 진행 막대를 그려요. 상태로 걸러 볼 수 있어요.Show levels with folder icons and branch lines, draw status badges and progress bars in other columns, and filter by status.
코드Code
탭을 골라 코드를 복사하세요. 위 화면은 이 코드를 그대로 실행한 결과예요.Pick a tab and copy the code. The preview above runs exactly this code.
이 화면은 새 모양 옵션을 켠 모양이에요: density: 'spacious', iconStyle: 'soft', motion: true (코드에 없으면 기본 모양으로 보여요)This preview has the new-look options on: density: 'spacious', iconStyle: 'soft', motion: true (without them in your code you get the default look)
버튼을 누르면 이 예제의 코드가 StackBlitz나 CodeSandbox로 전송돼요. 누르기 전에는 아무것도 보내지 않아요.
<div id="app">
<div class="toolbar">
<select aria-label="상태" id="status">
<option value="all" selected>전체</option>
<option value="progress">진행</option>
<option value="done">완료</option>
<option value="blocked">막힘</option>
</select>
<button type="button" id="expandAll">모두 펼치기</button>
<button type="button" id="collapseAll">모두 접기</button>
</div>
<div id="grid" style="height: 330px"></div>
</div>
<script type="module" src="./main.js"></script>import { createGrid } from 'maxgrid';
import { actions, options } from './example';
const api = createGrid(document.getElementById('grid'), options);
document.getElementById('status').addEventListener('change', (event) => actions.status(api, event.target.value));
document.getElementById('expandAll').addEventListener('click', () => actions.expandAll(api));
document.getElementById('collapseAll').addEventListener('click', () => actions.collapseAll(api));// 상태 배지와 진행 막대는 테마 변수 위에 색을 섞어서, 밝은·어두운 테마 모두에서 글자가 잘 보여요.
const tones = { 완료: '#1a7f37', 진행: '#1a56c4', 막힘: '#cf222e' };
const badge = () => {
let chip;
return {
mount(el, ctx) {
const box = document.createElement('div');
box.className = 'mxg-cell-center';
el.append(box);
chip = document.createElement('span');
chip.style.cssText =
'box-sizing:border-box;height:20px;line-height:18px;padding:0 8px;border-radius:10px;font-size:12px;white-space:nowrap;color:var(--mxg-fg)';
box.append(chip);
this.update(ctx);
},
update(ctx) {
chip.textContent = ctx.text;
chip.style.background = `color-mix(in srgb, ${tones[ctx.text] ?? '#57606a'} 28%, var(--mxg-bg))`;
chip.style.border = `1px solid color-mix(in srgb, ${tones[ctx.text] ?? '#57606a'} 55%, var(--mxg-bg))`;
},
destroy() { },
};
};
const bar = () => {
let fill;
let label;
return {
mount(el, ctx) {
// 칸(el)의 style을 통째로 바꾸면 그리드가 넣은 위치·크기 값이 지워져요. 안에 상자를 하나 두고 그 상자만 꾸며요.
const box = document.createElement('div');
box.className = 'mxg-cell-center';
box.style.gap = '8px';
el.append(box);
const track = document.createElement('div');
// 바탕(트랙)은 글자색을 조금 섞어서 밝은·어두운 화면 모두에서 보여요.
track.style.cssText =
'flex:1;height:8px;border-radius:4px;background:color-mix(in srgb, var(--mxg-fg) 22%, var(--mxg-bg));overflow:hidden';
fill = document.createElement('div');
fill.style.cssText = 'height:100%;background:var(--mxg-accent)';
track.append(fill);
label = document.createElement('span');
label.style.cssText = 'min-width:34px;text-align:end;font-size:12px;color:var(--mxg-fg)';
box.append(track, label);
this.update(ctx);
},
update(ctx) {
const percent = Math.min(100, Math.max(0, Number(ctx.value)));
fill.style.width = `${percent}%`;
label.textContent = `${percent}%`;
},
destroy() { },
};
};
// 폴더 아이콘과 가지선(├ └)을 쓴 업무 트리예요. 배지와 막대는 다른 컬럼에 달고, 트리 컬럼은 기본 칸이라 화살표가 나와요.
export const options = {
columns: [
{ id: 'name', title: '업무', width: 230 },
{ id: 'owner', title: '담당', width: 80 },
{ id: 'status', title: '상태', width: 90, cellRenderer: badge },
{ id: 'done', title: '진행률', width: 140, cellRenderer: bar },
],
rows: [
{ id: 1, parentId: null, name: '2.0 출시', owner: '김서연', status: '진행', done: 60 },
{ id: 2, parentId: 1, name: '데이터 이전', owner: '이준호', status: '완료', done: 100 },
{ id: 3, parentId: 1, name: '새 편집기', owner: '박민지', status: '진행', done: 55 },
{ id: 4, parentId: 3, name: '입력 검증', owner: '박민지', status: '진행', done: 70 },
{ id: 5, parentId: 3, name: '붙여넣기', owner: '최도윤', status: '막힘', done: 20 },
{ id: 6, parentId: 1, name: '결제 연동', owner: '정하은', status: '막힘', done: 20 },
{ id: 7, parentId: null, name: '문서', owner: '강지후', status: '진행', done: 40 },
{ id: 8, parentId: 7, name: '시작 안내', owner: '강지후', status: '완료', done: 100 },
{ id: 9, parentId: 7, name: '예제 모음', owner: '조수빈', status: '진행', done: 25 },
],
rowKey: 'id',
tree: {
parentKey: 'parentId',
column: 'name',
expandDepth: 'all',
toggleIcon: 'folder',
guides: 'solid',
guideStyle: 'branch',
},
};
// 상태 목록은 영문 id를 넘겨요. 표의 상태 글자로 바꿔서 걸러요.
const statusById = { progress: '진행', done: '완료', blocked: '막힘' };
export const actions = {
status: (api, value) => api.setFilterModel(value && statusById[value]
? {
match: 'all',
items: [{ columnId: 'status', operator: 'equals', value: statusById[value] }],
}
: null),
expandAll: (api) => api.expandAll(),
collapseAll: (api) => api.collapseAll(),
};<!doctype html>
<html lang="ko">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>업무 트리: 폴더 아이콘·가지선·상태 배지·진행 막대</title>
</head>
<body>
<div class="toolbar">
<select aria-label="상태" id="status">
<option value="all" selected>전체</option>
<option value="progress">진행</option>
<option value="done">완료</option>
<option value="blocked">막힘</option>
</select>
<button type="button" id="expandAll">모두 펼치기</button>
<button type="button" id="collapseAll">모두 접기</button>
</div>
<div id="grid" style="height: 330px"></div>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script>
// 상태 배지와 진행 막대는 테마 변수 위에 색을 섞어서, 밝은·어두운 테마 모두에서 글자가 잘 보여요.
const tones = { 완료: '#1a7f37', 진행: '#1a56c4', 막힘: '#cf222e' };
const badge = () => {
let chip;
return {
mount(el, ctx) {
const box = document.createElement('div');
box.className = 'mxg-cell-center';
el.append(box);
chip = document.createElement('span');
chip.style.cssText =
'box-sizing:border-box;height:20px;line-height:18px;padding:0 8px;border-radius:10px;font-size:12px;white-space:nowrap;color:var(--mxg-fg)';
box.append(chip);
this.update(ctx);
},
update(ctx) {
chip.textContent = ctx.text;
chip.style.background = `color-mix(in srgb, ${tones[ctx.text] ?? '#57606a'} 28%, var(--mxg-bg))`;
chip.style.border = `1px solid color-mix(in srgb, ${tones[ctx.text] ?? '#57606a'} 55%, var(--mxg-bg))`;
},
destroy() { },
};
};
const bar = () => {
let fill;
let label;
return {
mount(el, ctx) {
// 칸(el)의 style을 통째로 바꾸면 그리드가 넣은 위치·크기 값이 지워져요. 안에 상자를 하나 두고 그 상자만 꾸며요.
const box = document.createElement('div');
box.className = 'mxg-cell-center';
box.style.gap = '8px';
el.append(box);
const track = document.createElement('div');
// 바탕(트랙)은 글자색을 조금 섞어서 밝은·어두운 화면 모두에서 보여요.
track.style.cssText =
'flex:1;height:8px;border-radius:4px;background:color-mix(in srgb, var(--mxg-fg) 22%, var(--mxg-bg));overflow:hidden';
fill = document.createElement('div');
fill.style.cssText = 'height:100%;background:var(--mxg-accent)';
track.append(fill);
label = document.createElement('span');
label.style.cssText = 'min-width:34px;text-align:end;font-size:12px;color:var(--mxg-fg)';
box.append(track, label);
this.update(ctx);
},
update(ctx) {
const percent = Math.min(100, Math.max(0, Number(ctx.value)));
fill.style.width = `${percent}%`;
label.textContent = `${percent}%`;
},
destroy() { },
};
};
// 폴더 아이콘과 가지선(├ └)을 쓴 업무 트리예요. 배지와 막대는 다른 컬럼에 달고, 트리 컬럼은 기본 칸이라 화살표가 나와요.
const options = {
columns: [
{ id: 'name', title: '업무', width: 230 },
{ id: 'owner', title: '담당', width: 80 },
{ id: 'status', title: '상태', width: 90, cellRenderer: badge },
{ id: 'done', title: '진행률', width: 140, cellRenderer: bar },
],
rows: [
{ id: 1, parentId: null, name: '2.0 출시', owner: '김서연', status: '진행', done: 60 },
{ id: 2, parentId: 1, name: '데이터 이전', owner: '이준호', status: '완료', done: 100 },
{ id: 3, parentId: 1, name: '새 편집기', owner: '박민지', status: '진행', done: 55 },
{ id: 4, parentId: 3, name: '입력 검증', owner: '박민지', status: '진행', done: 70 },
{ id: 5, parentId: 3, name: '붙여넣기', owner: '최도윤', status: '막힘', done: 20 },
{ id: 6, parentId: 1, name: '결제 연동', owner: '정하은', status: '막힘', done: 20 },
{ id: 7, parentId: null, name: '문서', owner: '강지후', status: '진행', done: 40 },
{ id: 8, parentId: 7, name: '시작 안내', owner: '강지후', status: '완료', done: 100 },
{ id: 9, parentId: 7, name: '예제 모음', owner: '조수빈', status: '진행', done: 25 },
],
rowKey: 'id',
tree: {
parentKey: 'parentId',
column: 'name',
expandDepth: 'all',
toggleIcon: 'folder',
guides: 'solid',
guideStyle: 'branch',
},
};
// 상태 목록은 영문 id를 넘겨요. 표의 상태 글자로 바꿔서 걸러요.
const statusById = { progress: '진행', done: '완료', blocked: '막힘' };
const actions = {
status: (api, value) => api.setFilterModel(value && statusById[value]
? {
match: 'all',
items: [{ columnId: 'status', operator: 'equals', value: statusById[value] }],
}
: null),
expandAll: (api) => api.expandAll(),
collapseAll: (api) => api.collapseAll(),
};
options.ariaLabel = "업무 트리: 폴더 아이콘·가지선·상태 배지·진행 막대";
const api = MaxGrid.createGrid(document.getElementById('grid'), options);
document.getElementById('status').addEventListener('change', (event) => actions.status(api, event.target.value));
document.getElementById('expandAll').addEventListener('click', () => actions.expandAll(api));
document.getElementById('collapseAll').addEventListener('click', () => actions.collapseAll(api));
</script>
</body>
</html>버튼을 누르면 이 예제의 코드가 StackBlitz나 CodeSandbox로 전송돼요. 누르기 전에는 아무것도 보내지 않아요.
import { Grid, useGridApi } from '@maxgrid/react';
import { actions, options, type Row } from './example';
export function ExampleGrid() {
const [api, gridRef] = useGridApi<Row>();
return (
<>
<div className="toolbar">
<select
aria-label="상태"
disabled={!api}
onChange={(event) => api && actions.status(api, event.target.value)}
>
<option value="all">전체</option>
<option value="progress">진행</option>
<option value="done">완료</option>
<option value="blocked">막힘</option>
</select>
<button
type="button"
disabled={!api}
onClick={() => api && actions.expandAll(api)}
>모두 펼치기</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.collapseAll(api)}
>모두 접기</button>
</div>
<Grid style={{ height: 330 }} ref={gridRef} options={options} />
</>
);
}import type { CellRendererAdapter, GridApi, GridOptions } from '@maxgrid/react';
export interface Row {
id: number;
parentId: number | null;
name: string;
owner: string;
status: string;
done: number;
}
// 상태 배지와 진행 막대는 테마 변수 위에 색을 섞어서, 밝은·어두운 테마 모두에서 글자가 잘 보여요.
const tones: Record<string, string> = { 완료: '#1a7f37', 진행: '#1a56c4', 막힘: '#cf222e' };
const badge = (): CellRendererAdapter<Row> => {
let chip: HTMLSpanElement;
return {
mount(el, ctx) {
const box = document.createElement('div');
box.className = 'mxg-cell-center';
el.append(box);
chip = document.createElement('span');
chip.style.cssText =
'box-sizing:border-box;height:20px;line-height:18px;padding:0 8px;border-radius:10px;font-size:12px;white-space:nowrap;color:var(--mxg-fg)';
box.append(chip);
this.update(ctx);
},
update(ctx) {
chip.textContent = ctx.text;
chip.style.background = `color-mix(in srgb, ${tones[ctx.text] ?? '#57606a'} 28%, var(--mxg-bg))`;
chip.style.border = `1px solid color-mix(in srgb, ${tones[ctx.text] ?? '#57606a'} 55%, var(--mxg-bg))`;
},
destroy() {},
};
};
const bar = (): CellRendererAdapter<Row> => {
let fill: HTMLDivElement;
let label: HTMLSpanElement;
return {
mount(el, ctx) {
// 칸(el)의 style을 통째로 바꾸면 그리드가 넣은 위치·크기 값이 지워져요. 안에 상자를 하나 두고 그 상자만 꾸며요.
const box = document.createElement('div');
box.className = 'mxg-cell-center';
box.style.gap = '8px';
el.append(box);
const track = document.createElement('div');
// 바탕(트랙)은 글자색을 조금 섞어서 밝은·어두운 화면 모두에서 보여요.
track.style.cssText =
'flex:1;height:8px;border-radius:4px;background:color-mix(in srgb, var(--mxg-fg) 22%, var(--mxg-bg));overflow:hidden';
fill = document.createElement('div');
fill.style.cssText = 'height:100%;background:var(--mxg-accent)';
track.append(fill);
label = document.createElement('span');
label.style.cssText = 'min-width:34px;text-align:end;font-size:12px;color:var(--mxg-fg)';
box.append(track, label);
this.update(ctx);
},
update(ctx) {
const percent = Math.min(100, Math.max(0, Number(ctx.value)));
fill.style.width = `${percent}%`;
label.textContent = `${percent}%`;
},
destroy() {},
};
};
// 폴더 아이콘과 가지선(├ └)을 쓴 업무 트리예요. 배지와 막대는 다른 컬럼에 달고, 트리 컬럼은 기본 칸이라 화살표가 나와요.
export const options: GridOptions<Row> = {
columns: [
{ id: 'name', title: '업무', width: 230 },
{ id: 'owner', title: '담당', width: 80 },
{ id: 'status', title: '상태', width: 90, cellRenderer: badge },
{ id: 'done', title: '진행률', width: 140, cellRenderer: bar },
],
rows: [
{ id: 1, parentId: null, name: '2.0 출시', owner: '김서연', status: '진행', done: 60 },
{ id: 2, parentId: 1, name: '데이터 이전', owner: '이준호', status: '완료', done: 100 },
{ id: 3, parentId: 1, name: '새 편집기', owner: '박민지', status: '진행', done: 55 },
{ id: 4, parentId: 3, name: '입력 검증', owner: '박민지', status: '진행', done: 70 },
{ id: 5, parentId: 3, name: '붙여넣기', owner: '최도윤', status: '막힘', done: 20 },
{ id: 6, parentId: 1, name: '결제 연동', owner: '정하은', status: '막힘', done: 20 },
{ id: 7, parentId: null, name: '문서', owner: '강지후', status: '진행', done: 40 },
{ id: 8, parentId: 7, name: '시작 안내', owner: '강지후', status: '완료', done: 100 },
{ id: 9, parentId: 7, name: '예제 모음', owner: '조수빈', status: '진행', done: 25 },
],
rowKey: 'id',
tree: {
parentKey: 'parentId',
column: 'name',
expandDepth: 'all',
toggleIcon: 'folder',
guides: 'solid',
guideStyle: 'branch',
},
};
// 상태 목록은 영문 id를 넘겨요. 표의 상태 글자로 바꿔서 걸러요.
const statusById: Record<string, string> = { progress: '진행', done: '완료', blocked: '막힘' };
export const actions = {
status: (api: GridApi<Row>, value?: string) =>
api.setFilterModel(
value && statusById[value]
? {
match: 'all',
items: [{ columnId: 'status', operator: 'equals', value: statusById[value] }],
}
: null,
),
expandAll: (api: GridApi<Row>) => api.expandAll(),
collapseAll: (api: GridApi<Row>) => api.collapseAll(),
};버튼을 누르면 이 예제의 코드가 StackBlitz나 CodeSandbox로 전송돼요. 누르기 전에는 아무것도 보내지 않아요.
<script setup lang="ts">
import { shallowRef } from 'vue';
import { Grid, type GridApi } from '@maxgrid/vue';
import { actions, options, type Row } from './example';
const api = shallowRef<GridApi<Row> | null>(null);
function onReady(event: { api: GridApi<Row> }) {
api.value = event.api;
}
</script>
<template>
<div class="toolbar">
<select
aria-label="상태"
:disabled="!api"
@change="api && actions.status(api, ($event.target as HTMLSelectElement).value)"
>
<option value="all" selected>전체</option>
<option value="progress">진행</option>
<option value="done">완료</option>
<option value="blocked">막힘</option>
</select>
<button
type="button"
:disabled="!api"
@click="api && actions.expandAll(api)"
>모두 펼치기</button>
<button
type="button"
:disabled="!api"
@click="api && actions.collapseAll(api)"
>모두 접기</button>
</div>
<Grid style="height: 330px" :options="options" @ready="onReady" />
</template>import type { CellRendererAdapter, GridApi, GridOptions } from '@maxgrid/vue';
export interface Row {
id: number;
parentId: number | null;
name: string;
owner: string;
status: string;
done: number;
}
// 상태 배지와 진행 막대는 테마 변수 위에 색을 섞어서, 밝은·어두운 테마 모두에서 글자가 잘 보여요.
const tones: Record<string, string> = { 완료: '#1a7f37', 진행: '#1a56c4', 막힘: '#cf222e' };
const badge = (): CellRendererAdapter<Row> => {
let chip: HTMLSpanElement;
return {
mount(el, ctx) {
const box = document.createElement('div');
box.className = 'mxg-cell-center';
el.append(box);
chip = document.createElement('span');
chip.style.cssText =
'box-sizing:border-box;height:20px;line-height:18px;padding:0 8px;border-radius:10px;font-size:12px;white-space:nowrap;color:var(--mxg-fg)';
box.append(chip);
this.update(ctx);
},
update(ctx) {
chip.textContent = ctx.text;
chip.style.background = `color-mix(in srgb, ${tones[ctx.text] ?? '#57606a'} 28%, var(--mxg-bg))`;
chip.style.border = `1px solid color-mix(in srgb, ${tones[ctx.text] ?? '#57606a'} 55%, var(--mxg-bg))`;
},
destroy() {},
};
};
const bar = (): CellRendererAdapter<Row> => {
let fill: HTMLDivElement;
let label: HTMLSpanElement;
return {
mount(el, ctx) {
// 칸(el)의 style을 통째로 바꾸면 그리드가 넣은 위치·크기 값이 지워져요. 안에 상자를 하나 두고 그 상자만 꾸며요.
const box = document.createElement('div');
box.className = 'mxg-cell-center';
box.style.gap = '8px';
el.append(box);
const track = document.createElement('div');
// 바탕(트랙)은 글자색을 조금 섞어서 밝은·어두운 화면 모두에서 보여요.
track.style.cssText =
'flex:1;height:8px;border-radius:4px;background:color-mix(in srgb, var(--mxg-fg) 22%, var(--mxg-bg));overflow:hidden';
fill = document.createElement('div');
fill.style.cssText = 'height:100%;background:var(--mxg-accent)';
track.append(fill);
label = document.createElement('span');
label.style.cssText = 'min-width:34px;text-align:end;font-size:12px;color:var(--mxg-fg)';
box.append(track, label);
this.update(ctx);
},
update(ctx) {
const percent = Math.min(100, Math.max(0, Number(ctx.value)));
fill.style.width = `${percent}%`;
label.textContent = `${percent}%`;
},
destroy() {},
};
};
// 폴더 아이콘과 가지선(├ └)을 쓴 업무 트리예요. 배지와 막대는 다른 컬럼에 달고, 트리 컬럼은 기본 칸이라 화살표가 나와요.
export const options: GridOptions<Row> = {
columns: [
{ id: 'name', title: '업무', width: 230 },
{ id: 'owner', title: '담당', width: 80 },
{ id: 'status', title: '상태', width: 90, cellRenderer: badge },
{ id: 'done', title: '진행률', width: 140, cellRenderer: bar },
],
rows: [
{ id: 1, parentId: null, name: '2.0 출시', owner: '김서연', status: '진행', done: 60 },
{ id: 2, parentId: 1, name: '데이터 이전', owner: '이준호', status: '완료', done: 100 },
{ id: 3, parentId: 1, name: '새 편집기', owner: '박민지', status: '진행', done: 55 },
{ id: 4, parentId: 3, name: '입력 검증', owner: '박민지', status: '진행', done: 70 },
{ id: 5, parentId: 3, name: '붙여넣기', owner: '최도윤', status: '막힘', done: 20 },
{ id: 6, parentId: 1, name: '결제 연동', owner: '정하은', status: '막힘', done: 20 },
{ id: 7, parentId: null, name: '문서', owner: '강지후', status: '진행', done: 40 },
{ id: 8, parentId: 7, name: '시작 안내', owner: '강지후', status: '완료', done: 100 },
{ id: 9, parentId: 7, name: '예제 모음', owner: '조수빈', status: '진행', done: 25 },
],
rowKey: 'id',
tree: {
parentKey: 'parentId',
column: 'name',
expandDepth: 'all',
toggleIcon: 'folder',
guides: 'solid',
guideStyle: 'branch',
},
};
// 상태 목록은 영문 id를 넘겨요. 표의 상태 글자로 바꿔서 걸러요.
const statusById: Record<string, string> = { progress: '진행', done: '완료', blocked: '막힘' };
export const actions = {
status: (api: GridApi<Row>, value?: string) =>
api.setFilterModel(
value && statusById[value]
? {
match: 'all',
items: [{ columnId: 'status', operator: 'equals', value: statusById[value] }],
}
: null,
),
expandAll: (api: GridApi<Row>) => api.expandAll(),
collapseAll: (api: GridApi<Row>) => api.collapseAll(),
};버튼을 누르면 이 예제의 코드가 StackBlitz나 CodeSandbox로 전송돼요. 누르기 전에는 아무것도 보내지 않아요.
import { Component } from '@angular/core';
import { GridComponent, isGridEvent, type GridApi, type GridEventMessage } from '@maxgrid/angular';
import { actions, options, type Row } from './example';
@Component({
selector: 'app-example-grid',
standalone: true,
imports: [GridComponent],
template: `
<div class="toolbar">
<select
aria-label="상태"
[disabled]="!api"
(change)="api && actions.status(api, $any($event.target).value)"
>
<option value="all" selected>전체</option>
<option value="progress">진행</option>
<option value="done">완료</option>
<option value="blocked">막힘</option>
</select>
<button
type="button"
[disabled]="!api"
(click)="api && actions.expandAll(api)"
>모두 펼치기</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.collapseAll(api)"
>모두 접기</button>
</div>
<mx-grid style="height: 330px" [options]="options" [events]="relayed" (gridEvent)="onEvent($event)" />
`,
})
export class ExampleGridComponent {
readonly options = options;
readonly actions = actions;
readonly relayed = ['ready'] as const;
api: GridApi<Row> | null = null;
onEvent(event: GridEventMessage<Row>): void {
if (isGridEvent(event, 'ready')) {
this.api = event.payload.api;
}
}
}import type { CellRendererAdapter, GridApi, GridOptions } from '@maxgrid/angular';
export interface Row {
id: number;
parentId: number | null;
name: string;
owner: string;
status: string;
done: number;
}
// 상태 배지와 진행 막대는 테마 변수 위에 색을 섞어서, 밝은·어두운 테마 모두에서 글자가 잘 보여요.
const tones: Record<string, string> = { 완료: '#1a7f37', 진행: '#1a56c4', 막힘: '#cf222e' };
const badge = (): CellRendererAdapter<Row> => {
let chip: HTMLSpanElement;
return {
mount(el, ctx) {
const box = document.createElement('div');
box.className = 'mxg-cell-center';
el.append(box);
chip = document.createElement('span');
chip.style.cssText =
'box-sizing:border-box;height:20px;line-height:18px;padding:0 8px;border-radius:10px;font-size:12px;white-space:nowrap;color:var(--mxg-fg)';
box.append(chip);
this.update(ctx);
},
update(ctx) {
chip.textContent = ctx.text;
chip.style.background = `color-mix(in srgb, ${tones[ctx.text] ?? '#57606a'} 28%, var(--mxg-bg))`;
chip.style.border = `1px solid color-mix(in srgb, ${tones[ctx.text] ?? '#57606a'} 55%, var(--mxg-bg))`;
},
destroy() {},
};
};
const bar = (): CellRendererAdapter<Row> => {
let fill: HTMLDivElement;
let label: HTMLSpanElement;
return {
mount(el, ctx) {
// 칸(el)의 style을 통째로 바꾸면 그리드가 넣은 위치·크기 값이 지워져요. 안에 상자를 하나 두고 그 상자만 꾸며요.
const box = document.createElement('div');
box.className = 'mxg-cell-center';
box.style.gap = '8px';
el.append(box);
const track = document.createElement('div');
// 바탕(트랙)은 글자색을 조금 섞어서 밝은·어두운 화면 모두에서 보여요.
track.style.cssText =
'flex:1;height:8px;border-radius:4px;background:color-mix(in srgb, var(--mxg-fg) 22%, var(--mxg-bg));overflow:hidden';
fill = document.createElement('div');
fill.style.cssText = 'height:100%;background:var(--mxg-accent)';
track.append(fill);
label = document.createElement('span');
label.style.cssText = 'min-width:34px;text-align:end;font-size:12px;color:var(--mxg-fg)';
box.append(track, label);
this.update(ctx);
},
update(ctx) {
const percent = Math.min(100, Math.max(0, Number(ctx.value)));
fill.style.width = `${percent}%`;
label.textContent = `${percent}%`;
},
destroy() {},
};
};
// 폴더 아이콘과 가지선(├ └)을 쓴 업무 트리예요. 배지와 막대는 다른 컬럼에 달고, 트리 컬럼은 기본 칸이라 화살표가 나와요.
export const options: GridOptions<Row> = {
columns: [
{ id: 'name', title: '업무', width: 230 },
{ id: 'owner', title: '담당', width: 80 },
{ id: 'status', title: '상태', width: 90, cellRenderer: badge },
{ id: 'done', title: '진행률', width: 140, cellRenderer: bar },
],
rows: [
{ id: 1, parentId: null, name: '2.0 출시', owner: '김서연', status: '진행', done: 60 },
{ id: 2, parentId: 1, name: '데이터 이전', owner: '이준호', status: '완료', done: 100 },
{ id: 3, parentId: 1, name: '새 편집기', owner: '박민지', status: '진행', done: 55 },
{ id: 4, parentId: 3, name: '입력 검증', owner: '박민지', status: '진행', done: 70 },
{ id: 5, parentId: 3, name: '붙여넣기', owner: '최도윤', status: '막힘', done: 20 },
{ id: 6, parentId: 1, name: '결제 연동', owner: '정하은', status: '막힘', done: 20 },
{ id: 7, parentId: null, name: '문서', owner: '강지후', status: '진행', done: 40 },
{ id: 8, parentId: 7, name: '시작 안내', owner: '강지후', status: '완료', done: 100 },
{ id: 9, parentId: 7, name: '예제 모음', owner: '조수빈', status: '진행', done: 25 },
],
rowKey: 'id',
tree: {
parentKey: 'parentId',
column: 'name',
expandDepth: 'all',
toggleIcon: 'folder',
guides: 'solid',
guideStyle: 'branch',
},
};
// 상태 목록은 영문 id를 넘겨요. 표의 상태 글자로 바꿔서 걸러요.
const statusById: Record<string, string> = { progress: '진행', done: '완료', blocked: '막힘' };
export const actions = {
status: (api: GridApi<Row>, value?: string) =>
api.setFilterModel(
value && statusById[value]
? {
match: 'all',
items: [{ columnId: 'status', operator: 'equals', value: statusById[value] }],
}
: null,
),
expandAll: (api: GridApi<Row>) => api.expandAll(),
collapseAll: (api: GridApi<Row>) => api.collapseAll(),
};When you click, the example code is sent to StackBlitz or CodeSandbox. Nothing is sent before you click.
<div id="app">
<div class="toolbar">
<select aria-label="Status" id="status">
<option value="all" selected>All</option>
<option value="progress">In progress</option>
<option value="done">Done</option>
<option value="blocked">Blocked</option>
</select>
<button type="button" id="expandAll">Expand all</button>
<button type="button" id="collapseAll">Collapse all</button>
</div>
<div id="grid" style="height: 330px"></div>
</div>
<script type="module" src="./main.js"></script>import { createGrid } from 'maxgrid';
import { actions, options } from './example';
const api = createGrid(document.getElementById('grid'), options);
document.getElementById('status').addEventListener('change', (event) => actions.status(api, event.target.value));
document.getElementById('expandAll').addEventListener('click', () => actions.expandAll(api));
document.getElementById('collapseAll').addEventListener('click', () => actions.collapseAll(api));// Status badges and progress bars blend their colors over the theme variables, so the text reads in both light and dark themes.
const tones = {
Done: '#1a7f37',
'In progress': '#1a56c4',
Blocked: '#cf222e',
};
const badge = () => {
let chip;
return {
mount(el, ctx) {
const box = document.createElement('div');
box.className = 'mxg-cell-center';
el.append(box);
chip = document.createElement('span');
chip.style.cssText =
'box-sizing:border-box;height:20px;line-height:18px;padding:0 8px;border-radius:10px;font-size:12px;white-space:nowrap;color:var(--mxg-fg)';
box.append(chip);
this.update(ctx);
},
update(ctx) {
chip.textContent = ctx.text;
chip.style.background = `color-mix(in srgb, ${tones[ctx.text] ?? '#57606a'} 28%, var(--mxg-bg))`;
chip.style.border = `1px solid color-mix(in srgb, ${tones[ctx.text] ?? '#57606a'} 55%, var(--mxg-bg))`;
},
destroy() { },
};
};
const bar = () => {
let fill;
let label;
return {
mount(el, ctx) {
// Replacing the whole style of the cell (el) would erase the position and size values the grid set. Put one box inside and style only that box.
const box = document.createElement('div');
box.className = 'mxg-cell-center';
box.style.gap = '8px';
el.append(box);
const track = document.createElement('div');
// The track mixes in a bit of the text color so it shows on both light and dark backgrounds.
track.style.cssText =
'flex:1;height:8px;border-radius:4px;background:color-mix(in srgb, var(--mxg-fg) 22%, var(--mxg-bg));overflow:hidden';
fill = document.createElement('div');
fill.style.cssText = 'height:100%;background:var(--mxg-accent)';
track.append(fill);
label = document.createElement('span');
label.style.cssText = 'min-width:34px;text-align:end;font-size:12px;color:var(--mxg-fg)';
box.append(track, label);
this.update(ctx);
},
update(ctx) {
const percent = Math.min(100, Math.max(0, Number(ctx.value)));
fill.style.width = `${percent}%`;
label.textContent = `${percent}%`;
},
destroy() { },
};
};
// A task tree with folder icons and branch lines (├ └). The badge and bar go on other columns, and the tree column keeps the default cell so the arrow shows.
export const options = {
columns: [
{ id: 'name', title: 'Task', width: 230 },
{ id: 'owner', title: 'Owner', width: 120 },
{ id: 'status', title: 'Status', width: 110, cellRenderer: badge },
{ id: 'done', title: 'Progress', width: 140, cellRenderer: bar },
],
rows: [
{
id: 1,
parentId: null,
name: '2.0 Release',
owner: 'Emma Stone',
status: 'In progress',
done: 60,
},
{ id: 2, parentId: 1, name: 'Data migration', owner: 'Liam Carter', status: 'Done', done: 100 },
{
id: 3,
parentId: 1,
name: 'New editor',
owner: 'Mia Parker',
status: 'In progress',
done: 55,
},
{
id: 4,
parentId: 3,
name: 'Input validation',
owner: 'Mia Parker',
status: 'In progress',
done: 70,
},
{ id: 5, parentId: 3, name: 'Paste', owner: 'Noah Davis', status: 'Blocked', done: 20 },
{
id: 6,
parentId: 1,
name: 'Payment integration',
owner: 'Ava Moore',
status: 'Blocked',
done: 20,
},
{ id: 7, parentId: null, name: 'Docs', owner: 'Jack Reed', status: 'In progress', done: 40 },
{ id: 8, parentId: 7, name: 'Getting started', owner: 'Jack Reed', status: 'Done', done: 100 },
{
id: 9,
parentId: 7,
name: 'Example gallery',
owner: 'Lily Brooks',
status: 'In progress',
done: 25,
},
],
rowKey: 'id',
tree: {
parentKey: 'parentId',
column: 'name',
expandDepth: 'all',
toggleIcon: 'folder',
guides: 'solid',
guideStyle: 'branch',
},
};
// The status control hands over English ids; map them to the status texts in the table.
const statusById = {
progress: 'In progress',
done: 'Done',
blocked: 'Blocked',
};
export const actions = {
status: (api, value) => {
const status = value ? (statusById[value] ?? 'all') : 'all';
api.setFilterModel(status !== 'all'
? { match: 'all', items: [{ columnId: 'status', operator: 'equals', value: status }] }
: null);
},
expandAll: (api) => api.expandAll(),
collapseAll: (api) => api.collapseAll(),
};<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Task tree: folder icons, branch lines, status badges and progress bars</title>
</head>
<body>
<div class="toolbar">
<select aria-label="Status" id="status">
<option value="all" selected>All</option>
<option value="progress">In progress</option>
<option value="done">Done</option>
<option value="blocked">Blocked</option>
</select>
<button type="button" id="expandAll">Expand all</button>
<button type="button" id="collapseAll">Collapse all</button>
</div>
<div id="grid" style="height: 330px"></div>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script>
// Status badges and progress bars blend their colors over the theme variables, so the text reads in both light and dark themes.
const tones = {
Done: '#1a7f37',
'In progress': '#1a56c4',
Blocked: '#cf222e',
};
const badge = () => {
let chip;
return {
mount(el, ctx) {
const box = document.createElement('div');
box.className = 'mxg-cell-center';
el.append(box);
chip = document.createElement('span');
chip.style.cssText =
'box-sizing:border-box;height:20px;line-height:18px;padding:0 8px;border-radius:10px;font-size:12px;white-space:nowrap;color:var(--mxg-fg)';
box.append(chip);
this.update(ctx);
},
update(ctx) {
chip.textContent = ctx.text;
chip.style.background = `color-mix(in srgb, ${tones[ctx.text] ?? '#57606a'} 28%, var(--mxg-bg))`;
chip.style.border = `1px solid color-mix(in srgb, ${tones[ctx.text] ?? '#57606a'} 55%, var(--mxg-bg))`;
},
destroy() { },
};
};
const bar = () => {
let fill;
let label;
return {
mount(el, ctx) {
// Replacing the whole style of the cell (el) would erase the position and size values the grid set. Put one box inside and style only that box.
const box = document.createElement('div');
box.className = 'mxg-cell-center';
box.style.gap = '8px';
el.append(box);
const track = document.createElement('div');
// The track mixes in a bit of the text color so it shows on both light and dark backgrounds.
track.style.cssText =
'flex:1;height:8px;border-radius:4px;background:color-mix(in srgb, var(--mxg-fg) 22%, var(--mxg-bg));overflow:hidden';
fill = document.createElement('div');
fill.style.cssText = 'height:100%;background:var(--mxg-accent)';
track.append(fill);
label = document.createElement('span');
label.style.cssText = 'min-width:34px;text-align:end;font-size:12px;color:var(--mxg-fg)';
box.append(track, label);
this.update(ctx);
},
update(ctx) {
const percent = Math.min(100, Math.max(0, Number(ctx.value)));
fill.style.width = `${percent}%`;
label.textContent = `${percent}%`;
},
destroy() { },
};
};
// A task tree with folder icons and branch lines (├ └). The badge and bar go on other columns, and the tree column keeps the default cell so the arrow shows.
const options = {
columns: [
{ id: 'name', title: 'Task', width: 230 },
{ id: 'owner', title: 'Owner', width: 120 },
{ id: 'status', title: 'Status', width: 110, cellRenderer: badge },
{ id: 'done', title: 'Progress', width: 140, cellRenderer: bar },
],
rows: [
{
id: 1,
parentId: null,
name: '2.0 Release',
owner: 'Emma Stone',
status: 'In progress',
done: 60,
},
{ id: 2, parentId: 1, name: 'Data migration', owner: 'Liam Carter', status: 'Done', done: 100 },
{
id: 3,
parentId: 1,
name: 'New editor',
owner: 'Mia Parker',
status: 'In progress',
done: 55,
},
{
id: 4,
parentId: 3,
name: 'Input validation',
owner: 'Mia Parker',
status: 'In progress',
done: 70,
},
{ id: 5, parentId: 3, name: 'Paste', owner: 'Noah Davis', status: 'Blocked', done: 20 },
{
id: 6,
parentId: 1,
name: 'Payment integration',
owner: 'Ava Moore',
status: 'Blocked',
done: 20,
},
{ id: 7, parentId: null, name: 'Docs', owner: 'Jack Reed', status: 'In progress', done: 40 },
{ id: 8, parentId: 7, name: 'Getting started', owner: 'Jack Reed', status: 'Done', done: 100 },
{
id: 9,
parentId: 7,
name: 'Example gallery',
owner: 'Lily Brooks',
status: 'In progress',
done: 25,
},
],
rowKey: 'id',
tree: {
parentKey: 'parentId',
column: 'name',
expandDepth: 'all',
toggleIcon: 'folder',
guides: 'solid',
guideStyle: 'branch',
},
};
// The status control hands over English ids; map them to the status texts in the table.
const statusById = {
progress: 'In progress',
done: 'Done',
blocked: 'Blocked',
};
const actions = {
status: (api, value) => {
const status = value ? (statusById[value] ?? 'all') : 'all';
api.setFilterModel(status !== 'all'
? { match: 'all', items: [{ columnId: 'status', operator: 'equals', value: status }] }
: null);
},
expandAll: (api) => api.expandAll(),
collapseAll: (api) => api.collapseAll(),
};
options.ariaLabel = "Task tree: folder icons, branch lines, status badges and progress bars";
const api = MaxGrid.createGrid(document.getElementById('grid'), options);
document.getElementById('status').addEventListener('change', (event) => actions.status(api, event.target.value));
document.getElementById('expandAll').addEventListener('click', () => actions.expandAll(api));
document.getElementById('collapseAll').addEventListener('click', () => actions.collapseAll(api));
</script>
</body>
</html>When you click, the example code is sent to StackBlitz or CodeSandbox. Nothing is sent before you click.
import { Grid, useGridApi } from '@maxgrid/react';
import { actions, options, type Row } from './example';
export function ExampleGrid() {
const [api, gridRef] = useGridApi<Row>();
return (
<>
<div className="toolbar">
<select
aria-label="Status"
disabled={!api}
onChange={(event) => api && actions.status(api, event.target.value)}
>
<option value="all">All</option>
<option value="progress">In progress</option>
<option value="done">Done</option>
<option value="blocked">Blocked</option>
</select>
<button
type="button"
disabled={!api}
onClick={() => api && actions.expandAll(api)}
>Expand all</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.collapseAll(api)}
>Collapse all</button>
</div>
<Grid style={{ height: 330 }} ref={gridRef} options={options} />
</>
);
}import type { CellRendererAdapter, GridApi, GridOptions } from '@maxgrid/react';
export interface Row {
id: number;
parentId: number | null;
name: string;
owner: string;
status: string;
done: number;
}
// Status badges and progress bars blend their colors over the theme variables, so the text reads in both light and dark themes.
const tones: Record<string, string> = {
Done: '#1a7f37',
'In progress': '#1a56c4',
Blocked: '#cf222e',
};
const badge = (): CellRendererAdapter<Row> => {
let chip: HTMLSpanElement;
return {
mount(el, ctx) {
const box = document.createElement('div');
box.className = 'mxg-cell-center';
el.append(box);
chip = document.createElement('span');
chip.style.cssText =
'box-sizing:border-box;height:20px;line-height:18px;padding:0 8px;border-radius:10px;font-size:12px;white-space:nowrap;color:var(--mxg-fg)';
box.append(chip);
this.update(ctx);
},
update(ctx) {
chip.textContent = ctx.text;
chip.style.background = `color-mix(in srgb, ${tones[ctx.text] ?? '#57606a'} 28%, var(--mxg-bg))`;
chip.style.border = `1px solid color-mix(in srgb, ${tones[ctx.text] ?? '#57606a'} 55%, var(--mxg-bg))`;
},
destroy() {},
};
};
const bar = (): CellRendererAdapter<Row> => {
let fill: HTMLDivElement;
let label: HTMLSpanElement;
return {
mount(el, ctx) {
// Replacing the whole style of the cell (el) would erase the position and size values the grid set. Put one box inside and style only that box.
const box = document.createElement('div');
box.className = 'mxg-cell-center';
box.style.gap = '8px';
el.append(box);
const track = document.createElement('div');
// The track mixes in a bit of the text color so it shows on both light and dark backgrounds.
track.style.cssText =
'flex:1;height:8px;border-radius:4px;background:color-mix(in srgb, var(--mxg-fg) 22%, var(--mxg-bg));overflow:hidden';
fill = document.createElement('div');
fill.style.cssText = 'height:100%;background:var(--mxg-accent)';
track.append(fill);
label = document.createElement('span');
label.style.cssText = 'min-width:34px;text-align:end;font-size:12px;color:var(--mxg-fg)';
box.append(track, label);
this.update(ctx);
},
update(ctx) {
const percent = Math.min(100, Math.max(0, Number(ctx.value)));
fill.style.width = `${percent}%`;
label.textContent = `${percent}%`;
},
destroy() {},
};
};
// A task tree with folder icons and branch lines (├ └). The badge and bar go on other columns, and the tree column keeps the default cell so the arrow shows.
export const options: GridOptions<Row> = {
columns: [
{ id: 'name', title: 'Task', width: 230 },
{ id: 'owner', title: 'Owner', width: 120 },
{ id: 'status', title: 'Status', width: 110, cellRenderer: badge },
{ id: 'done', title: 'Progress', width: 140, cellRenderer: bar },
],
rows: [
{
id: 1,
parentId: null,
name: '2.0 Release',
owner: 'Emma Stone',
status: 'In progress',
done: 60,
},
{ id: 2, parentId: 1, name: 'Data migration', owner: 'Liam Carter', status: 'Done', done: 100 },
{
id: 3,
parentId: 1,
name: 'New editor',
owner: 'Mia Parker',
status: 'In progress',
done: 55,
},
{
id: 4,
parentId: 3,
name: 'Input validation',
owner: 'Mia Parker',
status: 'In progress',
done: 70,
},
{ id: 5, parentId: 3, name: 'Paste', owner: 'Noah Davis', status: 'Blocked', done: 20 },
{
id: 6,
parentId: 1,
name: 'Payment integration',
owner: 'Ava Moore',
status: 'Blocked',
done: 20,
},
{ id: 7, parentId: null, name: 'Docs', owner: 'Jack Reed', status: 'In progress', done: 40 },
{ id: 8, parentId: 7, name: 'Getting started', owner: 'Jack Reed', status: 'Done', done: 100 },
{
id: 9,
parentId: 7,
name: 'Example gallery',
owner: 'Lily Brooks',
status: 'In progress',
done: 25,
},
],
rowKey: 'id',
tree: {
parentKey: 'parentId',
column: 'name',
expandDepth: 'all',
toggleIcon: 'folder',
guides: 'solid',
guideStyle: 'branch',
},
};
// The status control hands over English ids; map them to the status texts in the table.
const statusById: Record<string, string> = {
progress: 'In progress',
done: 'Done',
blocked: 'Blocked',
};
export const actions = {
status: (api: GridApi<Row>, value?: string) => {
const status = value ? (statusById[value] ?? 'all') : 'all';
api.setFilterModel(
status !== 'all'
? { match: 'all', items: [{ columnId: 'status', operator: 'equals', value: status }] }
: null,
);
},
expandAll: (api: GridApi<Row>) => api.expandAll(),
collapseAll: (api: GridApi<Row>) => api.collapseAll(),
};When you click, the example code is sent to StackBlitz or CodeSandbox. Nothing is sent before you click.
<script setup lang="ts">
import { shallowRef } from 'vue';
import { Grid, type GridApi } from '@maxgrid/vue';
import { actions, options, type Row } from './example';
const api = shallowRef<GridApi<Row> | null>(null);
function onReady(event: { api: GridApi<Row> }) {
api.value = event.api;
}
</script>
<template>
<div class="toolbar">
<select
aria-label="Status"
:disabled="!api"
@change="api && actions.status(api, ($event.target as HTMLSelectElement).value)"
>
<option value="all" selected>All</option>
<option value="progress">In progress</option>
<option value="done">Done</option>
<option value="blocked">Blocked</option>
</select>
<button
type="button"
:disabled="!api"
@click="api && actions.expandAll(api)"
>Expand all</button>
<button
type="button"
:disabled="!api"
@click="api && actions.collapseAll(api)"
>Collapse all</button>
</div>
<Grid style="height: 330px" :options="options" @ready="onReady" />
</template>import type { CellRendererAdapter, GridApi, GridOptions } from '@maxgrid/vue';
export interface Row {
id: number;
parentId: number | null;
name: string;
owner: string;
status: string;
done: number;
}
// Status badges and progress bars blend their colors over the theme variables, so the text reads in both light and dark themes.
const tones: Record<string, string> = {
Done: '#1a7f37',
'In progress': '#1a56c4',
Blocked: '#cf222e',
};
const badge = (): CellRendererAdapter<Row> => {
let chip: HTMLSpanElement;
return {
mount(el, ctx) {
const box = document.createElement('div');
box.className = 'mxg-cell-center';
el.append(box);
chip = document.createElement('span');
chip.style.cssText =
'box-sizing:border-box;height:20px;line-height:18px;padding:0 8px;border-radius:10px;font-size:12px;white-space:nowrap;color:var(--mxg-fg)';
box.append(chip);
this.update(ctx);
},
update(ctx) {
chip.textContent = ctx.text;
chip.style.background = `color-mix(in srgb, ${tones[ctx.text] ?? '#57606a'} 28%, var(--mxg-bg))`;
chip.style.border = `1px solid color-mix(in srgb, ${tones[ctx.text] ?? '#57606a'} 55%, var(--mxg-bg))`;
},
destroy() {},
};
};
const bar = (): CellRendererAdapter<Row> => {
let fill: HTMLDivElement;
let label: HTMLSpanElement;
return {
mount(el, ctx) {
// Replacing the whole style of the cell (el) would erase the position and size values the grid set. Put one box inside and style only that box.
const box = document.createElement('div');
box.className = 'mxg-cell-center';
box.style.gap = '8px';
el.append(box);
const track = document.createElement('div');
// The track mixes in a bit of the text color so it shows on both light and dark backgrounds.
track.style.cssText =
'flex:1;height:8px;border-radius:4px;background:color-mix(in srgb, var(--mxg-fg) 22%, var(--mxg-bg));overflow:hidden';
fill = document.createElement('div');
fill.style.cssText = 'height:100%;background:var(--mxg-accent)';
track.append(fill);
label = document.createElement('span');
label.style.cssText = 'min-width:34px;text-align:end;font-size:12px;color:var(--mxg-fg)';
box.append(track, label);
this.update(ctx);
},
update(ctx) {
const percent = Math.min(100, Math.max(0, Number(ctx.value)));
fill.style.width = `${percent}%`;
label.textContent = `${percent}%`;
},
destroy() {},
};
};
// A task tree with folder icons and branch lines (├ └). The badge and bar go on other columns, and the tree column keeps the default cell so the arrow shows.
export const options: GridOptions<Row> = {
columns: [
{ id: 'name', title: 'Task', width: 230 },
{ id: 'owner', title: 'Owner', width: 120 },
{ id: 'status', title: 'Status', width: 110, cellRenderer: badge },
{ id: 'done', title: 'Progress', width: 140, cellRenderer: bar },
],
rows: [
{
id: 1,
parentId: null,
name: '2.0 Release',
owner: 'Emma Stone',
status: 'In progress',
done: 60,
},
{ id: 2, parentId: 1, name: 'Data migration', owner: 'Liam Carter', status: 'Done', done: 100 },
{
id: 3,
parentId: 1,
name: 'New editor',
owner: 'Mia Parker',
status: 'In progress',
done: 55,
},
{
id: 4,
parentId: 3,
name: 'Input validation',
owner: 'Mia Parker',
status: 'In progress',
done: 70,
},
{ id: 5, parentId: 3, name: 'Paste', owner: 'Noah Davis', status: 'Blocked', done: 20 },
{
id: 6,
parentId: 1,
name: 'Payment integration',
owner: 'Ava Moore',
status: 'Blocked',
done: 20,
},
{ id: 7, parentId: null, name: 'Docs', owner: 'Jack Reed', status: 'In progress', done: 40 },
{ id: 8, parentId: 7, name: 'Getting started', owner: 'Jack Reed', status: 'Done', done: 100 },
{
id: 9,
parentId: 7,
name: 'Example gallery',
owner: 'Lily Brooks',
status: 'In progress',
done: 25,
},
],
rowKey: 'id',
tree: {
parentKey: 'parentId',
column: 'name',
expandDepth: 'all',
toggleIcon: 'folder',
guides: 'solid',
guideStyle: 'branch',
},
};
// The status control hands over English ids; map them to the status texts in the table.
const statusById: Record<string, string> = {
progress: 'In progress',
done: 'Done',
blocked: 'Blocked',
};
export const actions = {
status: (api: GridApi<Row>, value?: string) => {
const status = value ? (statusById[value] ?? 'all') : 'all';
api.setFilterModel(
status !== 'all'
? { match: 'all', items: [{ columnId: 'status', operator: 'equals', value: status }] }
: null,
);
},
expandAll: (api: GridApi<Row>) => api.expandAll(),
collapseAll: (api: GridApi<Row>) => api.collapseAll(),
};When you click, the example code is sent to StackBlitz or CodeSandbox. Nothing is sent before you click.
import { Component } from '@angular/core';
import { GridComponent, isGridEvent, type GridApi, type GridEventMessage } from '@maxgrid/angular';
import { actions, options, type Row } from './example';
@Component({
selector: 'app-example-grid',
standalone: true,
imports: [GridComponent],
template: `
<div class="toolbar">
<select
aria-label="Status"
[disabled]="!api"
(change)="api && actions.status(api, $any($event.target).value)"
>
<option value="all" selected>All</option>
<option value="progress">In progress</option>
<option value="done">Done</option>
<option value="blocked">Blocked</option>
</select>
<button
type="button"
[disabled]="!api"
(click)="api && actions.expandAll(api)"
>Expand all</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.collapseAll(api)"
>Collapse all</button>
</div>
<mx-grid style="height: 330px" [options]="options" [events]="relayed" (gridEvent)="onEvent($event)" />
`,
})
export class ExampleGridComponent {
readonly options = options;
readonly actions = actions;
readonly relayed = ['ready'] as const;
api: GridApi<Row> | null = null;
onEvent(event: GridEventMessage<Row>): void {
if (isGridEvent(event, 'ready')) {
this.api = event.payload.api;
}
}
}import type { CellRendererAdapter, GridApi, GridOptions } from '@maxgrid/angular';
export interface Row {
id: number;
parentId: number | null;
name: string;
owner: string;
status: string;
done: number;
}
// Status badges and progress bars blend their colors over the theme variables, so the text reads in both light and dark themes.
const tones: Record<string, string> = {
Done: '#1a7f37',
'In progress': '#1a56c4',
Blocked: '#cf222e',
};
const badge = (): CellRendererAdapter<Row> => {
let chip: HTMLSpanElement;
return {
mount(el, ctx) {
const box = document.createElement('div');
box.className = 'mxg-cell-center';
el.append(box);
chip = document.createElement('span');
chip.style.cssText =
'box-sizing:border-box;height:20px;line-height:18px;padding:0 8px;border-radius:10px;font-size:12px;white-space:nowrap;color:var(--mxg-fg)';
box.append(chip);
this.update(ctx);
},
update(ctx) {
chip.textContent = ctx.text;
chip.style.background = `color-mix(in srgb, ${tones[ctx.text] ?? '#57606a'} 28%, var(--mxg-bg))`;
chip.style.border = `1px solid color-mix(in srgb, ${tones[ctx.text] ?? '#57606a'} 55%, var(--mxg-bg))`;
},
destroy() {},
};
};
const bar = (): CellRendererAdapter<Row> => {
let fill: HTMLDivElement;
let label: HTMLSpanElement;
return {
mount(el, ctx) {
// Replacing the whole style of the cell (el) would erase the position and size values the grid set. Put one box inside and style only that box.
const box = document.createElement('div');
box.className = 'mxg-cell-center';
box.style.gap = '8px';
el.append(box);
const track = document.createElement('div');
// The track mixes in a bit of the text color so it shows on both light and dark backgrounds.
track.style.cssText =
'flex:1;height:8px;border-radius:4px;background:color-mix(in srgb, var(--mxg-fg) 22%, var(--mxg-bg));overflow:hidden';
fill = document.createElement('div');
fill.style.cssText = 'height:100%;background:var(--mxg-accent)';
track.append(fill);
label = document.createElement('span');
label.style.cssText = 'min-width:34px;text-align:end;font-size:12px;color:var(--mxg-fg)';
box.append(track, label);
this.update(ctx);
},
update(ctx) {
const percent = Math.min(100, Math.max(0, Number(ctx.value)));
fill.style.width = `${percent}%`;
label.textContent = `${percent}%`;
},
destroy() {},
};
};
// A task tree with folder icons and branch lines (├ └). The badge and bar go on other columns, and the tree column keeps the default cell so the arrow shows.
export const options: GridOptions<Row> = {
columns: [
{ id: 'name', title: 'Task', width: 230 },
{ id: 'owner', title: 'Owner', width: 120 },
{ id: 'status', title: 'Status', width: 110, cellRenderer: badge },
{ id: 'done', title: 'Progress', width: 140, cellRenderer: bar },
],
rows: [
{
id: 1,
parentId: null,
name: '2.0 Release',
owner: 'Emma Stone',
status: 'In progress',
done: 60,
},
{ id: 2, parentId: 1, name: 'Data migration', owner: 'Liam Carter', status: 'Done', done: 100 },
{
id: 3,
parentId: 1,
name: 'New editor',
owner: 'Mia Parker',
status: 'In progress',
done: 55,
},
{
id: 4,
parentId: 3,
name: 'Input validation',
owner: 'Mia Parker',
status: 'In progress',
done: 70,
},
{ id: 5, parentId: 3, name: 'Paste', owner: 'Noah Davis', status: 'Blocked', done: 20 },
{
id: 6,
parentId: 1,
name: 'Payment integration',
owner: 'Ava Moore',
status: 'Blocked',
done: 20,
},
{ id: 7, parentId: null, name: 'Docs', owner: 'Jack Reed', status: 'In progress', done: 40 },
{ id: 8, parentId: 7, name: 'Getting started', owner: 'Jack Reed', status: 'Done', done: 100 },
{
id: 9,
parentId: 7,
name: 'Example gallery',
owner: 'Lily Brooks',
status: 'In progress',
done: 25,
},
],
rowKey: 'id',
tree: {
parentKey: 'parentId',
column: 'name',
expandDepth: 'all',
toggleIcon: 'folder',
guides: 'solid',
guideStyle: 'branch',
},
};
// The status control hands over English ids; map them to the status texts in the table.
const statusById: Record<string, string> = {
progress: 'In progress',
done: 'Done',
blocked: 'Blocked',
};
export const actions = {
status: (api: GridApi<Row>, value?: string) => {
const status = value ? (statusById[value] ?? 'all') : 'all';
api.setFilterModel(
status !== 'all'
? { match: 'all', items: [{ columnId: 'status', operator: 'equals', value: status }] }
: null,
);
},
expandAll: (api: GridApi<Row>) => api.expandAll(),
collapseAll: (api: GridApi<Row>) => api.collapseAll(),
};