진행 막대: 두께·글자 위치·퍼센트Progress bars: thickness, label position, percent
막대 두께와 간격, 글자를 앞·뒤·막대 안에 놓기, 0~1 비율 값, 퍼센트 글자, 구간별 클래스를 옵션만으로 바꿔요.Change bar thickness and gap, put the label before, after or inside the bar, use 0–1 ratios, percent text and per-band classes with options only.
코드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="position">
<option value="end" selected>막대 뒤</option>
<option value="start">막대 앞</option>
<option value="inside">막대 안</option>
<option value="none">숨김</option>
</select>
<select aria-label="막대 두께" id="thick">
<option value="8" selected>기본 (8px)</option>
<option value="16">16px</option>
<option value="4">4px</option>
</select>
</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('position').addEventListener('change', (event) => actions.position(api, event.target.value));
document.getElementById('thick').addEventListener('change', (event) => actions.thick(api, event.target.value));const rows = [
{ id: 1, task: '설계', done: 100, ratio: 1 },
{ id: 2, task: '개발', done: 72, ratio: 0.72 },
{ id: 3, task: '시험', done: 35.5, ratio: 0.355 },
{ id: 4, task: '배포', done: 8, ratio: 0.08 },
{ id: 5, task: '문서', done: 0, ratio: 0 },
];
let position = 'end';
let height = 8;
const columns = () => [
{ id: 'task', title: '작업', width: 110 },
{
id: 'done',
title: '진행률',
width: 260,
cellRenderer: 'progress',
cellRendererParams: {
height,
labelPosition: position,
ranges: [
{ upTo: 30, tone: 'danger', className: 'band-low' },
{ upTo: 70, tone: 'warning' },
{ upTo: 100, tone: 'success' },
],
},
},
{
id: 'ratio',
title: '비율 (0~1)',
width: 240,
cellRenderer: 'progress',
cellRendererParams: { scale: 'ratio', label: 'percent', precision: 1, height, gap: 12 },
},
];
export const options = {
columns: columns(),
rows,
rowKey: 'id',
saveMode: 'none',
};
let say = () => { };
export function setup(_api, log) {
say = log;
position = 'end';
height = 8;
log({
ko: '두 번째 열은 0~1 값을 퍼센트 글자(소수 1자리)로 보여요.',
en: 'The second column shows 0–1 values as percent text with one decimal.',
});
}
export const actions = {
position: (api, value) => {
position = (value ?? 'end');
api.setColumns(columns());
say({ ko: `글자 위치: ${position}`, en: `Label position: ${position}` });
},
thick: (api, value) => {
height = Number(value ?? 8);
api.setColumns(columns());
say({ ko: `막대 두께: ${height}px`, en: `Bar thickness: ${height}px` });
},
};<!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="position">
<option value="end" selected>막대 뒤</option>
<option value="start">막대 앞</option>
<option value="inside">막대 안</option>
<option value="none">숨김</option>
</select>
<select aria-label="막대 두께" id="thick">
<option value="8" selected>기본 (8px)</option>
<option value="16">16px</option>
<option value="4">4px</option>
</select>
</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, task: '설계', done: 100, ratio: 1 },
{ id: 2, task: '개발', done: 72, ratio: 0.72 },
{ id: 3, task: '시험', done: 35.5, ratio: 0.355 },
{ id: 4, task: '배포', done: 8, ratio: 0.08 },
{ id: 5, task: '문서', done: 0, ratio: 0 },
];
let position = 'end';
let height = 8;
const columns = () => [
{ id: 'task', title: '작업', width: 110 },
{
id: 'done',
title: '진행률',
width: 260,
cellRenderer: 'progress',
cellRendererParams: {
height,
labelPosition: position,
ranges: [
{ upTo: 30, tone: 'danger', className: 'band-low' },
{ upTo: 70, tone: 'warning' },
{ upTo: 100, tone: 'success' },
],
},
},
{
id: 'ratio',
title: '비율 (0~1)',
width: 240,
cellRenderer: 'progress',
cellRendererParams: { scale: 'ratio', label: 'percent', precision: 1, height, gap: 12 },
},
];
const options = {
columns: columns(),
rows,
rowKey: 'id',
saveMode: 'none',
};
let say = () => { };
function setup(_api, log) {
say = log;
position = 'end';
height = 8;
log({
ko: '두 번째 열은 0~1 값을 퍼센트 글자(소수 1자리)로 보여요.',
en: 'The second column shows 0–1 values as percent text with one decimal.',
});
}
const actions = {
position: (api, value) => {
position = (value ?? 'end');
api.setColumns(columns());
say({ ko: `글자 위치: ${position}`, en: `Label position: ${position}` });
},
thick: (api, value) => {
height = Number(value ?? 8);
api.setColumns(columns());
say({ ko: `막대 두께: ${height}px`, en: `Bar thickness: ${height}px` });
},
};
options.ariaLabel = "진행 막대: 두께·글자 위치·퍼센트";
const api = MaxGrid.createGrid(document.getElementById('grid'), options);
setup(api, (message) => {
const item = document.createElement('li');
item.textContent =
typeof message === 'string' ? message : navigator.language.startsWith('ko') ? message.ko : message.en;
document.getElementById('log').prepend(item);
});
document.getElementById('position').addEventListener('change', (event) => actions.position(api, event.target.value));
document.getElementById('thick').addEventListener('change', (event) => actions.thick(api, event.target.value));
</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">
<select
aria-label="글자 위치"
disabled={!api}
onChange={(event) => api && actions.position(api, event.target.value)}
>
<option value="end">막대 뒤</option>
<option value="start">막대 앞</option>
<option value="inside">막대 안</option>
<option value="none">숨김</option>
</select>
<select defaultValue="end"
aria-label="막대 두께"
disabled={!api}
onChange={(event) => api && actions.thick(api, event.target.value)}
>
<option value="8">기본 (8px)</option>
<option value="16">16px</option>
<option value="4">4px</option>
</select>
</div>
<Grid style={{ height: 300 }} ref={gridRef} options={options} />
</>
);
}import type { ColumnDef, GridApi, GridOptions } from '@maxgrid/react';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
task: string;
done: number;
ratio: number;
}
const rows: Row[] = [
{ id: 1, task: '설계', done: 100, ratio: 1 },
{ id: 2, task: '개발', done: 72, ratio: 0.72 },
{ id: 3, task: '시험', done: 35.5, ratio: 0.355 },
{ id: 4, task: '배포', done: 8, ratio: 0.08 },
{ id: 5, task: '문서', done: 0, ratio: 0 },
];
let position: 'end' | 'start' | 'inside' | 'none' = 'end';
let height = 8;
const columns = (): ColumnDef<Row>[] => [
{ id: 'task', title: '작업', width: 110 },
{
id: 'done',
title: '진행률',
width: 260,
cellRenderer: 'progress',
cellRendererParams: {
height,
labelPosition: position,
ranges: [
{ upTo: 30, tone: 'danger', className: 'band-low' },
{ upTo: 70, tone: 'warning' },
{ upTo: 100, tone: 'success' },
],
},
},
{
id: 'ratio',
title: '비율 (0~1)',
width: 240,
cellRenderer: 'progress',
cellRendererParams: { scale: 'ratio', label: 'percent', precision: 1, height, gap: 12 },
},
];
export const options: GridOptions<Row> = {
columns: columns(),
rows,
rowKey: 'id',
saveMode: 'none',
};
let say: (message: LogText) => void = () => {};
export function setup(_api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
position = 'end';
height = 8;
log({
ko: '두 번째 열은 0~1 값을 퍼센트 글자(소수 1자리)로 보여요.',
en: 'The second column shows 0–1 values as percent text with one decimal.',
});
}
export const actions = {
position: (api: GridApi<Row>, value?: string) => {
position = (value ?? 'end') as typeof position;
api.setColumns(columns());
say({ ko: `글자 위치: ${position}`, en: `Label position: ${position}` });
},
thick: (api: GridApi<Row>, value?: string) => {
height = Number(value ?? 8);
api.setColumns(columns());
say({ ko: `막대 두께: ${height}px`, en: `Bar thickness: ${height}px` });
},
};버튼을 누르면 이 예제의 코드가 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">
<select
aria-label="글자 위치"
:disabled="!api"
@change="api && actions.position(api, ($event.target as HTMLSelectElement).value)"
>
<option value="end" selected>막대 뒤</option>
<option value="start">막대 앞</option>
<option value="inside">막대 안</option>
<option value="none">숨김</option>
</select>
<select
aria-label="막대 두께"
:disabled="!api"
@change="api && actions.thick(api, ($event.target as HTMLSelectElement).value)"
>
<option value="8" selected>기본 (8px)</option>
<option value="16">16px</option>
<option value="4">4px</option>
</select>
</div>
<Grid style="height: 300px" :options="options" @ready="onReady" />
</template>import type { ColumnDef, GridApi, GridOptions } from '@maxgrid/vue';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
task: string;
done: number;
ratio: number;
}
const rows: Row[] = [
{ id: 1, task: '설계', done: 100, ratio: 1 },
{ id: 2, task: '개발', done: 72, ratio: 0.72 },
{ id: 3, task: '시험', done: 35.5, ratio: 0.355 },
{ id: 4, task: '배포', done: 8, ratio: 0.08 },
{ id: 5, task: '문서', done: 0, ratio: 0 },
];
let position: 'end' | 'start' | 'inside' | 'none' = 'end';
let height = 8;
const columns = (): ColumnDef<Row>[] => [
{ id: 'task', title: '작업', width: 110 },
{
id: 'done',
title: '진행률',
width: 260,
cellRenderer: 'progress',
cellRendererParams: {
height,
labelPosition: position,
ranges: [
{ upTo: 30, tone: 'danger', className: 'band-low' },
{ upTo: 70, tone: 'warning' },
{ upTo: 100, tone: 'success' },
],
},
},
{
id: 'ratio',
title: '비율 (0~1)',
width: 240,
cellRenderer: 'progress',
cellRendererParams: { scale: 'ratio', label: 'percent', precision: 1, height, gap: 12 },
},
];
export const options: GridOptions<Row> = {
columns: columns(),
rows,
rowKey: 'id',
saveMode: 'none',
};
let say: (message: LogText) => void = () => {};
export function setup(_api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
position = 'end';
height = 8;
log({
ko: '두 번째 열은 0~1 값을 퍼센트 글자(소수 1자리)로 보여요.',
en: 'The second column shows 0–1 values as percent text with one decimal.',
});
}
export const actions = {
position: (api: GridApi<Row>, value?: string) => {
position = (value ?? 'end') as typeof position;
api.setColumns(columns());
say({ ko: `글자 위치: ${position}`, en: `Label position: ${position}` });
},
thick: (api: GridApi<Row>, value?: string) => {
height = Number(value ?? 8);
api.setColumns(columns());
say({ ko: `막대 두께: ${height}px`, en: `Bar thickness: ${height}px` });
},
};버튼을 누르면 이 예제의 코드가 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">
<select
aria-label="글자 위치"
[disabled]="!api"
(change)="api && actions.position(api, $any($event.target).value)"
>
<option value="end" selected>막대 뒤</option>
<option value="start">막대 앞</option>
<option value="inside">막대 안</option>
<option value="none">숨김</option>
</select>
<select
aria-label="막대 두께"
[disabled]="!api"
(change)="api && actions.thick(api, $any($event.target).value)"
>
<option value="8" selected>기본 (8px)</option>
<option value="16">16px</option>
<option value="4">4px</option>
</select>
</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 { ColumnDef, GridApi, GridOptions } from '@maxgrid/angular';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
task: string;
done: number;
ratio: number;
}
const rows: Row[] = [
{ id: 1, task: '설계', done: 100, ratio: 1 },
{ id: 2, task: '개발', done: 72, ratio: 0.72 },
{ id: 3, task: '시험', done: 35.5, ratio: 0.355 },
{ id: 4, task: '배포', done: 8, ratio: 0.08 },
{ id: 5, task: '문서', done: 0, ratio: 0 },
];
let position: 'end' | 'start' | 'inside' | 'none' = 'end';
let height = 8;
const columns = (): ColumnDef<Row>[] => [
{ id: 'task', title: '작업', width: 110 },
{
id: 'done',
title: '진행률',
width: 260,
cellRenderer: 'progress',
cellRendererParams: {
height,
labelPosition: position,
ranges: [
{ upTo: 30, tone: 'danger', className: 'band-low' },
{ upTo: 70, tone: 'warning' },
{ upTo: 100, tone: 'success' },
],
},
},
{
id: 'ratio',
title: '비율 (0~1)',
width: 240,
cellRenderer: 'progress',
cellRendererParams: { scale: 'ratio', label: 'percent', precision: 1, height, gap: 12 },
},
];
export const options: GridOptions<Row> = {
columns: columns(),
rows,
rowKey: 'id',
saveMode: 'none',
};
let say: (message: LogText) => void = () => {};
export function setup(_api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
position = 'end';
height = 8;
log({
ko: '두 번째 열은 0~1 값을 퍼센트 글자(소수 1자리)로 보여요.',
en: 'The second column shows 0–1 values as percent text with one decimal.',
});
}
export const actions = {
position: (api: GridApi<Row>, value?: string) => {
position = (value ?? 'end') as typeof position;
api.setColumns(columns());
say({ ko: `글자 위치: ${position}`, en: `Label position: ${position}` });
},
thick: (api: GridApi<Row>, value?: string) => {
height = Number(value ?? 8);
api.setColumns(columns());
say({ ko: `막대 두께: ${height}px`, en: `Bar thickness: ${height}px` });
},
};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="Label position" id="position">
<option value="end" selected>After the bar</option>
<option value="start">Before the bar</option>
<option value="inside">Inside the bar</option>
<option value="none">Hidden</option>
</select>
<select aria-label="Bar thickness" id="thick">
<option value="8" selected>Default (8px)</option>
<option value="16">16px</option>
<option value="4">4px</option>
</select>
</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('position').addEventListener('change', (event) => actions.position(api, event.target.value));
document.getElementById('thick').addEventListener('change', (event) => actions.thick(api, event.target.value));const rows = [
{ id: 1, task: 'Design', done: 100, ratio: 1 },
{ id: 2, task: 'Development', done: 72, ratio: 0.72 },
{ id: 3, task: 'Testing', done: 35.5, ratio: 0.355 },
{ id: 4, task: 'Deployment', done: 8, ratio: 0.08 },
{ id: 5, task: 'Docs', done: 0, ratio: 0 },
];
let position = 'end';
let height = 8;
const columns = () => [
{ id: 'task', title: 'Task', width: 120 },
{
id: 'done',
title: 'Progress',
width: 260,
cellRenderer: 'progress',
cellRendererParams: {
height,
labelPosition: position,
ranges: [
{ upTo: 30, tone: 'danger', className: 'band-low' },
{ upTo: 70, tone: 'warning' },
{ upTo: 100, tone: 'success' },
],
},
},
{
id: 'ratio',
title: 'Ratio (0-1)',
width: 240,
cellRenderer: 'progress',
cellRendererParams: { scale: 'ratio', label: 'percent', precision: 1, height, gap: 12 },
},
];
export const options = {
columns: columns(),
rows,
rowKey: 'id',
saveMode: 'none',
};
let say = () => { };
export function setup(_api, log) {
say = log;
position = 'end';
height = 8;
log('The second column shows 0–1 values as percent text with one decimal.');
}
export const actions = {
position: (api, value) => {
position = (value ?? 'end');
api.setColumns(columns());
say(`Label position: ${position}`);
},
thick: (api, value) => {
height = Number(value ?? 8);
api.setColumns(columns());
say(`Bar thickness: ${height}px`);
},
};<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Progress bars: thickness, label position, percent</title>
</head>
<body>
<div class="toolbar">
<select aria-label="Label position" id="position">
<option value="end" selected>After the bar</option>
<option value="start">Before the bar</option>
<option value="inside">Inside the bar</option>
<option value="none">Hidden</option>
</select>
<select aria-label="Bar thickness" id="thick">
<option value="8" selected>Default (8px)</option>
<option value="16">16px</option>
<option value="4">4px</option>
</select>
</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, task: 'Design', done: 100, ratio: 1 },
{ id: 2, task: 'Development', done: 72, ratio: 0.72 },
{ id: 3, task: 'Testing', done: 35.5, ratio: 0.355 },
{ id: 4, task: 'Deployment', done: 8, ratio: 0.08 },
{ id: 5, task: 'Docs', done: 0, ratio: 0 },
];
let position = 'end';
let height = 8;
const columns = () => [
{ id: 'task', title: 'Task', width: 120 },
{
id: 'done',
title: 'Progress',
width: 260,
cellRenderer: 'progress',
cellRendererParams: {
height,
labelPosition: position,
ranges: [
{ upTo: 30, tone: 'danger', className: 'band-low' },
{ upTo: 70, tone: 'warning' },
{ upTo: 100, tone: 'success' },
],
},
},
{
id: 'ratio',
title: 'Ratio (0-1)',
width: 240,
cellRenderer: 'progress',
cellRendererParams: { scale: 'ratio', label: 'percent', precision: 1, height, gap: 12 },
},
];
const options = {
columns: columns(),
rows,
rowKey: 'id',
saveMode: 'none',
};
let say = () => { };
function setup(_api, log) {
say = log;
position = 'end';
height = 8;
log('The second column shows 0–1 values as percent text with one decimal.');
}
const actions = {
position: (api, value) => {
position = (value ?? 'end');
api.setColumns(columns());
say(`Label position: ${position}`);
},
thick: (api, value) => {
height = Number(value ?? 8);
api.setColumns(columns());
say(`Bar thickness: ${height}px`);
},
};
options.ariaLabel = "Progress bars: thickness, label position, percent";
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('position').addEventListener('change', (event) => actions.position(api, event.target.value));
document.getElementById('thick').addEventListener('change', (event) => actions.thick(api, event.target.value));
</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">
<select
aria-label="Label position"
disabled={!api}
onChange={(event) => api && actions.position(api, event.target.value)}
>
<option value="end">After the bar</option>
<option value="start">Before the bar</option>
<option value="inside">Inside the bar</option>
<option value="none">Hidden</option>
</select>
<select defaultValue="end"
aria-label="Bar thickness"
disabled={!api}
onChange={(event) => api && actions.thick(api, event.target.value)}
>
<option value="8">Default (8px)</option>
<option value="16">16px</option>
<option value="4">4px</option>
</select>
</div>
<Grid style={{ height: 300 }} ref={gridRef} options={options} />
</>
);
}import type { ColumnDef, GridApi, GridOptions } from '@maxgrid/react';
export type LogText = string;
export interface Row {
id: number;
task: string;
done: number;
ratio: number;
}
const rows: Row[] = [
{ id: 1, task: 'Design', done: 100, ratio: 1 },
{ id: 2, task: 'Development', done: 72, ratio: 0.72 },
{ id: 3, task: 'Testing', done: 35.5, ratio: 0.355 },
{ id: 4, task: 'Deployment', done: 8, ratio: 0.08 },
{ id: 5, task: 'Docs', done: 0, ratio: 0 },
];
let position: 'end' | 'start' | 'inside' | 'none' = 'end';
let height = 8;
const columns = (): ColumnDef<Row>[] => [
{ id: 'task', title: 'Task', width: 120 },
{
id: 'done',
title: 'Progress',
width: 260,
cellRenderer: 'progress',
cellRendererParams: {
height,
labelPosition: position,
ranges: [
{ upTo: 30, tone: 'danger', className: 'band-low' },
{ upTo: 70, tone: 'warning' },
{ upTo: 100, tone: 'success' },
],
},
},
{
id: 'ratio',
title: 'Ratio (0-1)',
width: 240,
cellRenderer: 'progress',
cellRendererParams: { scale: 'ratio', label: 'percent', precision: 1, height, gap: 12 },
},
];
export const options: GridOptions<Row> = {
columns: columns(),
rows,
rowKey: 'id',
saveMode: 'none',
};
let say: (message: LogText) => void = () => {};
export function setup(_api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
position = 'end';
height = 8;
log('The second column shows 0–1 values as percent text with one decimal.');
}
export const actions = {
position: (api: GridApi<Row>, value?: string) => {
position = (value ?? 'end') as typeof position;
api.setColumns(columns());
say(`Label position: ${position}`);
},
thick: (api: GridApi<Row>, value?: string) => {
height = Number(value ?? 8);
api.setColumns(columns());
say(`Bar thickness: ${height}px`);
},
};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">
<select
aria-label="Label position"
:disabled="!api"
@change="api && actions.position(api, ($event.target as HTMLSelectElement).value)"
>
<option value="end" selected>After the bar</option>
<option value="start">Before the bar</option>
<option value="inside">Inside the bar</option>
<option value="none">Hidden</option>
</select>
<select
aria-label="Bar thickness"
:disabled="!api"
@change="api && actions.thick(api, ($event.target as HTMLSelectElement).value)"
>
<option value="8" selected>Default (8px)</option>
<option value="16">16px</option>
<option value="4">4px</option>
</select>
</div>
<Grid style="height: 300px" :options="options" @ready="onReady" />
</template>import type { ColumnDef, GridApi, GridOptions } from '@maxgrid/vue';
export type LogText = string;
export interface Row {
id: number;
task: string;
done: number;
ratio: number;
}
const rows: Row[] = [
{ id: 1, task: 'Design', done: 100, ratio: 1 },
{ id: 2, task: 'Development', done: 72, ratio: 0.72 },
{ id: 3, task: 'Testing', done: 35.5, ratio: 0.355 },
{ id: 4, task: 'Deployment', done: 8, ratio: 0.08 },
{ id: 5, task: 'Docs', done: 0, ratio: 0 },
];
let position: 'end' | 'start' | 'inside' | 'none' = 'end';
let height = 8;
const columns = (): ColumnDef<Row>[] => [
{ id: 'task', title: 'Task', width: 120 },
{
id: 'done',
title: 'Progress',
width: 260,
cellRenderer: 'progress',
cellRendererParams: {
height,
labelPosition: position,
ranges: [
{ upTo: 30, tone: 'danger', className: 'band-low' },
{ upTo: 70, tone: 'warning' },
{ upTo: 100, tone: 'success' },
],
},
},
{
id: 'ratio',
title: 'Ratio (0-1)',
width: 240,
cellRenderer: 'progress',
cellRendererParams: { scale: 'ratio', label: 'percent', precision: 1, height, gap: 12 },
},
];
export const options: GridOptions<Row> = {
columns: columns(),
rows,
rowKey: 'id',
saveMode: 'none',
};
let say: (message: LogText) => void = () => {};
export function setup(_api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
position = 'end';
height = 8;
log('The second column shows 0–1 values as percent text with one decimal.');
}
export const actions = {
position: (api: GridApi<Row>, value?: string) => {
position = (value ?? 'end') as typeof position;
api.setColumns(columns());
say(`Label position: ${position}`);
},
thick: (api: GridApi<Row>, value?: string) => {
height = Number(value ?? 8);
api.setColumns(columns());
say(`Bar thickness: ${height}px`);
},
};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">
<select
aria-label="Label position"
[disabled]="!api"
(change)="api && actions.position(api, $any($event.target).value)"
>
<option value="end" selected>After the bar</option>
<option value="start">Before the bar</option>
<option value="inside">Inside the bar</option>
<option value="none">Hidden</option>
</select>
<select
aria-label="Bar thickness"
[disabled]="!api"
(change)="api && actions.thick(api, $any($event.target).value)"
>
<option value="8" selected>Default (8px)</option>
<option value="16">16px</option>
<option value="4">4px</option>
</select>
</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 { ColumnDef, GridApi, GridOptions } from '@maxgrid/angular';
export type LogText = string;
export interface Row {
id: number;
task: string;
done: number;
ratio: number;
}
const rows: Row[] = [
{ id: 1, task: 'Design', done: 100, ratio: 1 },
{ id: 2, task: 'Development', done: 72, ratio: 0.72 },
{ id: 3, task: 'Testing', done: 35.5, ratio: 0.355 },
{ id: 4, task: 'Deployment', done: 8, ratio: 0.08 },
{ id: 5, task: 'Docs', done: 0, ratio: 0 },
];
let position: 'end' | 'start' | 'inside' | 'none' = 'end';
let height = 8;
const columns = (): ColumnDef<Row>[] => [
{ id: 'task', title: 'Task', width: 120 },
{
id: 'done',
title: 'Progress',
width: 260,
cellRenderer: 'progress',
cellRendererParams: {
height,
labelPosition: position,
ranges: [
{ upTo: 30, tone: 'danger', className: 'band-low' },
{ upTo: 70, tone: 'warning' },
{ upTo: 100, tone: 'success' },
],
},
},
{
id: 'ratio',
title: 'Ratio (0-1)',
width: 240,
cellRenderer: 'progress',
cellRendererParams: { scale: 'ratio', label: 'percent', precision: 1, height, gap: 12 },
},
];
export const options: GridOptions<Row> = {
columns: columns(),
rows,
rowKey: 'id',
saveMode: 'none',
};
let say: (message: LogText) => void = () => {};
export function setup(_api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
position = 'end';
height = 8;
log('The second column shows 0–1 values as percent text with one decimal.');
}
export const actions = {
position: (api: GridApi<Row>, value?: string) => {
position = (value ?? 'end') as typeof position;
api.setColumns(columns());
say(`Label position: ${position}`);
},
thick: (api: GridApi<Row>, value?: string) => {
height = Number(value ?? 8);
api.setColumns(columns());
say(`Bar thickness: ${height}px`);
},
};