값이 바뀐 칸 번쩍이기Flash the cells whose value changed
옵션 changeFlash를 켜면 updateRows나 transact로 값이 바뀐 칸이 잠깐 번쩍여요. 컬럼의 flashOnChange로 칸 단위로 켜고 끌 수 있고, 사용자가 편집기에서 고친 칸은 번쩍이지 않아요.With the changeFlash option, cells whose value was changed by updateRows or transact flash briefly. flashOnChange turns it on or off per column, and cells the user edits in the editor do not flash.
코드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="tick">가격 한 번 바꾸기</button>
<button type="button" id="noteChange">메모 바꾸기</button>
<button type="button" id="live">실시간 시작/중지</button>
</div>
<div id="grid" style="height: 230px"></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('tick').addEventListener('click', () => actions.tick(api));
document.getElementById('noteChange').addEventListener('click', () => actions.noteChange(api));
document.getElementById('live').addEventListener('click', () => actions.live(api));const rows = [
{ id: 1, symbol: 'AAA', price: 100, note: '' },
{ id: 2, symbol: 'BBB', price: 250, note: '' },
{ id: 3, symbol: 'CCC', price: 75, note: '' },
{ id: 4, symbol: 'DDD', price: 410, note: '' },
];
let timer;
// changeFlash를 켜면 코드로 값이 바뀐 칸이 잠깐 번쩍여요. 가격은 flashOnChange로 켜져 있고 메모는 꺼 뒀어요.
export const options = {
columns: [
{ id: 'symbol', title: '종목', width: 100 },
{ id: 'price', title: '가격', kind: 'number', width: 120 },
{ id: 'note', title: '메모', width: 140, editable: true, flashOnChange: false },
],
rows,
rowKey: 'id',
changeFlash: { duration: 800, fade: 400 },
};
export function setup(api, log) {
log({
ko: '"가격 한 번 바꾸기"를 눌러 보세요. 바뀐 가격 칸만 번쩍여요. 메모 칸을 직접 고치면 번쩍이지 않아요.',
en: 'Press "Change one price": only the changed price cell flashes. Editing the memo cell by hand does not flash.',
});
return () => {
if (timer !== undefined)
clearInterval(timer);
timer = undefined;
};
}
export const actions = {
tick: (api) => {
const id = 1 + Math.floor(Math.random() * 4);
const row = api.getRowByKey(id);
if (row)
api.updateRows([{ ...row, price: Math.round(row.price * (0.9 + Math.random() * 0.2)) }]);
},
noteChange: (api) => {
const row = api.getRowByKey(2);
if (row)
api.updateRows([{ ...row, note: `${row.note}.` }]);
},
live: (api) => {
if (timer !== undefined) {
clearInterval(timer);
timer = undefined;
return;
}
timer = setInterval(() => actions.tick(api), 400);
},
};<!doctype html>
<html lang="ko">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>값이 바뀐 칸 번쩍이기</title>
</head>
<body>
<div class="toolbar">
<button type="button" id="tick">가격 한 번 바꾸기</button>
<button type="button" id="noteChange">메모 바꾸기</button>
<button type="button" id="live">실시간 시작/중지</button>
</div>
<div id="grid" style="height: 230px"></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, symbol: 'AAA', price: 100, note: '' },
{ id: 2, symbol: 'BBB', price: 250, note: '' },
{ id: 3, symbol: 'CCC', price: 75, note: '' },
{ id: 4, symbol: 'DDD', price: 410, note: '' },
];
let timer;
// changeFlash를 켜면 코드로 값이 바뀐 칸이 잠깐 번쩍여요. 가격은 flashOnChange로 켜져 있고 메모는 꺼 뒀어요.
const options = {
columns: [
{ id: 'symbol', title: '종목', width: 100 },
{ id: 'price', title: '가격', kind: 'number', width: 120 },
{ id: 'note', title: '메모', width: 140, editable: true, flashOnChange: false },
],
rows,
rowKey: 'id',
changeFlash: { duration: 800, fade: 400 },
};
function setup(api, log) {
log({
ko: '"가격 한 번 바꾸기"를 눌러 보세요. 바뀐 가격 칸만 번쩍여요. 메모 칸을 직접 고치면 번쩍이지 않아요.',
en: 'Press "Change one price": only the changed price cell flashes. Editing the memo cell by hand does not flash.',
});
return () => {
if (timer !== undefined)
clearInterval(timer);
timer = undefined;
};
}
const actions = {
tick: (api) => {
const id = 1 + Math.floor(Math.random() * 4);
const row = api.getRowByKey(id);
if (row)
api.updateRows([{ ...row, price: Math.round(row.price * (0.9 + Math.random() * 0.2)) }]);
},
noteChange: (api) => {
const row = api.getRowByKey(2);
if (row)
api.updateRows([{ ...row, note: `${row.note}.` }]);
},
live: (api) => {
if (timer !== undefined) {
clearInterval(timer);
timer = undefined;
return;
}
timer = setInterval(() => actions.tick(api), 400);
},
};
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('tick').addEventListener('click', () => actions.tick(api));
document.getElementById('noteChange').addEventListener('click', () => actions.noteChange(api));
document.getElementById('live').addEventListener('click', () => actions.live(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.tick(api)}
>가격 한 번 바꾸기</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.noteChange(api)}
>메모 바꾸기</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.live(api)}
>실시간 시작/중지</button>
</div>
<Grid style={{ height: 230 }} ref={gridRef} options={options} />
</>
);
}import type { GridApi, GridOptions } from '@maxgrid/react';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
symbol: string;
price: number;
note: string;
}
const rows: Row[] = [
{ id: 1, symbol: 'AAA', price: 100, note: '' },
{ id: 2, symbol: 'BBB', price: 250, note: '' },
{ id: 3, symbol: 'CCC', price: 75, note: '' },
{ id: 4, symbol: 'DDD', price: 410, note: '' },
];
let timer: ReturnType<typeof setInterval> | undefined;
// changeFlash를 켜면 코드로 값이 바뀐 칸이 잠깐 번쩍여요. 가격은 flashOnChange로 켜져 있고 메모는 꺼 뒀어요.
export const options: GridOptions<Row> = {
columns: [
{ id: 'symbol', title: '종목', width: 100 },
{ id: 'price', title: '가격', kind: 'number', width: 120 },
{ id: 'note', title: '메모', width: 140, editable: true, flashOnChange: false },
],
rows,
rowKey: 'id',
changeFlash: { duration: 800, fade: 400 },
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
log({
ko: '"가격 한 번 바꾸기"를 눌러 보세요. 바뀐 가격 칸만 번쩍여요. 메모 칸을 직접 고치면 번쩍이지 않아요.',
en: 'Press "Change one price": only the changed price cell flashes. Editing the memo cell by hand does not flash.',
});
return () => {
if (timer !== undefined) clearInterval(timer);
timer = undefined;
};
}
export const actions = {
tick: (api: GridApi<Row>) => {
const id = 1 + Math.floor(Math.random() * 4);
const row = api.getRowByKey(id);
if (row)
api.updateRows([{ ...row, price: Math.round(row.price * (0.9 + Math.random() * 0.2)) }]);
},
noteChange: (api: GridApi<Row>) => {
const row = api.getRowByKey(2);
if (row) api.updateRows([{ ...row, note: `${row.note}.` }]);
},
live: (api: GridApi<Row>) => {
if (timer !== undefined) {
clearInterval(timer);
timer = undefined;
return;
}
timer = setInterval(() => actions.tick(api), 400);
},
};버튼을 누르면 이 예제의 코드가 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.tick(api)">가격 한 번 바꾸기</button>
<button
type="button"
:disabled="!api"
@click="api && actions.noteChange(api)"
>메모 바꾸기</button>
<button type="button" :disabled="!api" @click="api && actions.live(api)">실시간 시작/중지</button>
</div>
<Grid style="height: 230px" :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;
symbol: string;
price: number;
note: string;
}
const rows: Row[] = [
{ id: 1, symbol: 'AAA', price: 100, note: '' },
{ id: 2, symbol: 'BBB', price: 250, note: '' },
{ id: 3, symbol: 'CCC', price: 75, note: '' },
{ id: 4, symbol: 'DDD', price: 410, note: '' },
];
let timer: ReturnType<typeof setInterval> | undefined;
// changeFlash를 켜면 코드로 값이 바뀐 칸이 잠깐 번쩍여요. 가격은 flashOnChange로 켜져 있고 메모는 꺼 뒀어요.
export const options: GridOptions<Row> = {
columns: [
{ id: 'symbol', title: '종목', width: 100 },
{ id: 'price', title: '가격', kind: 'number', width: 120 },
{ id: 'note', title: '메모', width: 140, editable: true, flashOnChange: false },
],
rows,
rowKey: 'id',
changeFlash: { duration: 800, fade: 400 },
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
log({
ko: '"가격 한 번 바꾸기"를 눌러 보세요. 바뀐 가격 칸만 번쩍여요. 메모 칸을 직접 고치면 번쩍이지 않아요.',
en: 'Press "Change one price": only the changed price cell flashes. Editing the memo cell by hand does not flash.',
});
return () => {
if (timer !== undefined) clearInterval(timer);
timer = undefined;
};
}
export const actions = {
tick: (api: GridApi<Row>) => {
const id = 1 + Math.floor(Math.random() * 4);
const row = api.getRowByKey(id);
if (row)
api.updateRows([{ ...row, price: Math.round(row.price * (0.9 + Math.random() * 0.2)) }]);
},
noteChange: (api: GridApi<Row>) => {
const row = api.getRowByKey(2);
if (row) api.updateRows([{ ...row, note: `${row.note}.` }]);
},
live: (api: GridApi<Row>) => {
if (timer !== undefined) {
clearInterval(timer);
timer = undefined;
return;
}
timer = setInterval(() => actions.tick(api), 400);
},
};버튼을 누르면 이 예제의 코드가 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.tick(api)"
>가격 한 번 바꾸기</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.noteChange(api)"
>메모 바꾸기</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.live(api)"
>실시간 시작/중지</button>
</div>
<mx-grid style="height: 230px" [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;
symbol: string;
price: number;
note: string;
}
const rows: Row[] = [
{ id: 1, symbol: 'AAA', price: 100, note: '' },
{ id: 2, symbol: 'BBB', price: 250, note: '' },
{ id: 3, symbol: 'CCC', price: 75, note: '' },
{ id: 4, symbol: 'DDD', price: 410, note: '' },
];
let timer: ReturnType<typeof setInterval> | undefined;
// changeFlash를 켜면 코드로 값이 바뀐 칸이 잠깐 번쩍여요. 가격은 flashOnChange로 켜져 있고 메모는 꺼 뒀어요.
export const options: GridOptions<Row> = {
columns: [
{ id: 'symbol', title: '종목', width: 100 },
{ id: 'price', title: '가격', kind: 'number', width: 120 },
{ id: 'note', title: '메모', width: 140, editable: true, flashOnChange: false },
],
rows,
rowKey: 'id',
changeFlash: { duration: 800, fade: 400 },
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
log({
ko: '"가격 한 번 바꾸기"를 눌러 보세요. 바뀐 가격 칸만 번쩍여요. 메모 칸을 직접 고치면 번쩍이지 않아요.',
en: 'Press "Change one price": only the changed price cell flashes. Editing the memo cell by hand does not flash.',
});
return () => {
if (timer !== undefined) clearInterval(timer);
timer = undefined;
};
}
export const actions = {
tick: (api: GridApi<Row>) => {
const id = 1 + Math.floor(Math.random() * 4);
const row = api.getRowByKey(id);
if (row)
api.updateRows([{ ...row, price: Math.round(row.price * (0.9 + Math.random() * 0.2)) }]);
},
noteChange: (api: GridApi<Row>) => {
const row = api.getRowByKey(2);
if (row) api.updateRows([{ ...row, note: `${row.note}.` }]);
},
live: (api: GridApi<Row>) => {
if (timer !== undefined) {
clearInterval(timer);
timer = undefined;
return;
}
timer = setInterval(() => actions.tick(api), 400);
},
};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="tick">Change one price</button>
<button type="button" id="noteChange">Change memo</button>
<button type="button" id="live">Start/stop live</button>
</div>
<div id="grid" style="height: 230px"></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('tick').addEventListener('click', () => actions.tick(api));
document.getElementById('noteChange').addEventListener('click', () => actions.noteChange(api));
document.getElementById('live').addEventListener('click', () => actions.live(api));const rows = [
{ id: 1, symbol: 'AAA', price: 100, note: '' },
{ id: 2, symbol: 'BBB', price: 250, note: '' },
{ id: 3, symbol: 'CCC', price: 75, note: '' },
{ id: 4, symbol: 'DDD', price: 410, note: '' },
];
let timer;
// With changeFlash on, cells changed from code flash briefly. Price flashes through flashOnChange; memo has it turned off.
export const options = {
columns: [
{ id: 'symbol', title: 'Symbol', width: 100 },
{ id: 'price', title: 'Price', kind: 'number', width: 120 },
{ id: 'note', title: 'Memo', width: 140, editable: true, flashOnChange: false },
],
rows,
rowKey: 'id',
changeFlash: { duration: 800, fade: 400 },
};
export function setup(api, log) {
log('Press "Change one price": only the changed price cell flashes. Editing the memo cell by hand does not flash.');
return () => {
if (timer !== undefined)
clearInterval(timer);
timer = undefined;
};
}
export const actions = {
tick: (api) => {
const id = 1 + Math.floor(Math.random() * 4);
const row = api.getRowByKey(id);
if (row)
api.updateRows([{ ...row, price: Math.round(row.price * (0.9 + Math.random() * 0.2)) }]);
},
noteChange: (api) => {
const row = api.getRowByKey(2);
if (row)
api.updateRows([{ ...row, note: `${row.note}.` }]);
},
live: (api) => {
if (timer !== undefined) {
clearInterval(timer);
timer = undefined;
return;
}
timer = setInterval(() => actions.tick(api), 400);
},
};<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Flash the cells whose value changed</title>
</head>
<body>
<div class="toolbar">
<button type="button" id="tick">Change one price</button>
<button type="button" id="noteChange">Change memo</button>
<button type="button" id="live">Start/stop live</button>
</div>
<div id="grid" style="height: 230px"></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, symbol: 'AAA', price: 100, note: '' },
{ id: 2, symbol: 'BBB', price: 250, note: '' },
{ id: 3, symbol: 'CCC', price: 75, note: '' },
{ id: 4, symbol: 'DDD', price: 410, note: '' },
];
let timer;
// With changeFlash on, cells changed from code flash briefly. Price flashes through flashOnChange; memo has it turned off.
const options = {
columns: [
{ id: 'symbol', title: 'Symbol', width: 100 },
{ id: 'price', title: 'Price', kind: 'number', width: 120 },
{ id: 'note', title: 'Memo', width: 140, editable: true, flashOnChange: false },
],
rows,
rowKey: 'id',
changeFlash: { duration: 800, fade: 400 },
};
function setup(api, log) {
log('Press "Change one price": only the changed price cell flashes. Editing the memo cell by hand does not flash.');
return () => {
if (timer !== undefined)
clearInterval(timer);
timer = undefined;
};
}
const actions = {
tick: (api) => {
const id = 1 + Math.floor(Math.random() * 4);
const row = api.getRowByKey(id);
if (row)
api.updateRows([{ ...row, price: Math.round(row.price * (0.9 + Math.random() * 0.2)) }]);
},
noteChange: (api) => {
const row = api.getRowByKey(2);
if (row)
api.updateRows([{ ...row, note: `${row.note}.` }]);
},
live: (api) => {
if (timer !== undefined) {
clearInterval(timer);
timer = undefined;
return;
}
timer = setInterval(() => actions.tick(api), 400);
},
};
options.ariaLabel = "Flash the cells whose value changed";
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('tick').addEventListener('click', () => actions.tick(api));
document.getElementById('noteChange').addEventListener('click', () => actions.noteChange(api));
document.getElementById('live').addEventListener('click', () => actions.live(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.tick(api)}
>Change one price</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.noteChange(api)}
>Change memo</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.live(api)}
>Start/stop live</button>
</div>
<Grid style={{ height: 230 }} ref={gridRef} options={options} />
</>
);
}import type { GridApi, GridOptions } from '@maxgrid/react';
export type LogText = string;
export interface Row {
id: number;
symbol: string;
price: number;
note: string;
}
const rows: Row[] = [
{ id: 1, symbol: 'AAA', price: 100, note: '' },
{ id: 2, symbol: 'BBB', price: 250, note: '' },
{ id: 3, symbol: 'CCC', price: 75, note: '' },
{ id: 4, symbol: 'DDD', price: 410, note: '' },
];
let timer: ReturnType<typeof setInterval> | undefined;
// With changeFlash on, cells changed from code flash briefly. Price flashes through flashOnChange; memo has it turned off.
export const options: GridOptions<Row> = {
columns: [
{ id: 'symbol', title: 'Symbol', width: 100 },
{ id: 'price', title: 'Price', kind: 'number', width: 120 },
{ id: 'note', title: 'Memo', width: 140, editable: true, flashOnChange: false },
],
rows,
rowKey: 'id',
changeFlash: { duration: 800, fade: 400 },
};
export function setup(api: GridApi<Row>, log: (message: string) => void) {
log(
'Press "Change one price": only the changed price cell flashes. Editing the memo cell by hand does not flash.',
);
return () => {
if (timer !== undefined) clearInterval(timer);
timer = undefined;
};
}
export const actions = {
tick: (api: GridApi<Row>) => {
const id = 1 + Math.floor(Math.random() * 4);
const row = api.getRowByKey(id);
if (row)
api.updateRows([{ ...row, price: Math.round(row.price * (0.9 + Math.random() * 0.2)) }]);
},
noteChange: (api: GridApi<Row>) => {
const row = api.getRowByKey(2);
if (row) api.updateRows([{ ...row, note: `${row.note}.` }]);
},
live: (api: GridApi<Row>) => {
if (timer !== undefined) {
clearInterval(timer);
timer = undefined;
return;
}
timer = setInterval(() => actions.tick(api), 400);
},
};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.tick(api)">Change one price</button>
<button
type="button"
:disabled="!api"
@click="api && actions.noteChange(api)"
>Change memo</button>
<button type="button" :disabled="!api" @click="api && actions.live(api)">Start/stop live</button>
</div>
<Grid style="height: 230px" :options="options" @ready="onReady" />
</template>import type { GridApi, GridOptions } from '@maxgrid/vue';
export type LogText = string;
export interface Row {
id: number;
symbol: string;
price: number;
note: string;
}
const rows: Row[] = [
{ id: 1, symbol: 'AAA', price: 100, note: '' },
{ id: 2, symbol: 'BBB', price: 250, note: '' },
{ id: 3, symbol: 'CCC', price: 75, note: '' },
{ id: 4, symbol: 'DDD', price: 410, note: '' },
];
let timer: ReturnType<typeof setInterval> | undefined;
// With changeFlash on, cells changed from code flash briefly. Price flashes through flashOnChange; memo has it turned off.
export const options: GridOptions<Row> = {
columns: [
{ id: 'symbol', title: 'Symbol', width: 100 },
{ id: 'price', title: 'Price', kind: 'number', width: 120 },
{ id: 'note', title: 'Memo', width: 140, editable: true, flashOnChange: false },
],
rows,
rowKey: 'id',
changeFlash: { duration: 800, fade: 400 },
};
export function setup(api: GridApi<Row>, log: (message: string) => void) {
log(
'Press "Change one price": only the changed price cell flashes. Editing the memo cell by hand does not flash.',
);
return () => {
if (timer !== undefined) clearInterval(timer);
timer = undefined;
};
}
export const actions = {
tick: (api: GridApi<Row>) => {
const id = 1 + Math.floor(Math.random() * 4);
const row = api.getRowByKey(id);
if (row)
api.updateRows([{ ...row, price: Math.round(row.price * (0.9 + Math.random() * 0.2)) }]);
},
noteChange: (api: GridApi<Row>) => {
const row = api.getRowByKey(2);
if (row) api.updateRows([{ ...row, note: `${row.note}.` }]);
},
live: (api: GridApi<Row>) => {
if (timer !== undefined) {
clearInterval(timer);
timer = undefined;
return;
}
timer = setInterval(() => actions.tick(api), 400);
},
};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.tick(api)"
>Change one price</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.noteChange(api)"
>Change memo</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.live(api)"
>Start/stop live</button>
</div>
<mx-grid style="height: 230px" [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;
export interface Row {
id: number;
symbol: string;
price: number;
note: string;
}
const rows: Row[] = [
{ id: 1, symbol: 'AAA', price: 100, note: '' },
{ id: 2, symbol: 'BBB', price: 250, note: '' },
{ id: 3, symbol: 'CCC', price: 75, note: '' },
{ id: 4, symbol: 'DDD', price: 410, note: '' },
];
let timer: ReturnType<typeof setInterval> | undefined;
// With changeFlash on, cells changed from code flash briefly. Price flashes through flashOnChange; memo has it turned off.
export const options: GridOptions<Row> = {
columns: [
{ id: 'symbol', title: 'Symbol', width: 100 },
{ id: 'price', title: 'Price', kind: 'number', width: 120 },
{ id: 'note', title: 'Memo', width: 140, editable: true, flashOnChange: false },
],
rows,
rowKey: 'id',
changeFlash: { duration: 800, fade: 400 },
};
export function setup(api: GridApi<Row>, log: (message: string) => void) {
log(
'Press "Change one price": only the changed price cell flashes. Editing the memo cell by hand does not flash.',
);
return () => {
if (timer !== undefined) clearInterval(timer);
timer = undefined;
};
}
export const actions = {
tick: (api: GridApi<Row>) => {
const id = 1 + Math.floor(Math.random() * 4);
const row = api.getRowByKey(id);
if (row)
api.updateRows([{ ...row, price: Math.round(row.price * (0.9 + Math.random() * 0.2)) }]);
},
noteChange: (api: GridApi<Row>) => {
const row = api.getRowByKey(2);
if (row) api.updateRows([{ ...row, note: `${row.note}.` }]);
},
live: (api: GridApi<Row>) => {
if (timer !== undefined) {
clearInterval(timer);
timer = undefined;
return;
}
timer = setInterval(() => actions.tick(api), 400);
},
};