본문으로 건너뛰기Skip to content
예제 첫화면Examples home

값이 바뀐 칸 번쩍이기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.

입문Beginner
직접 써 보기Live preview값이 바뀐 칸 번쩍이기Flash the cells whose value changed

코드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)

빌드 도구(Vite 등)를 쓰는 프로젝트용 모듈 파일이에요. 설치 없이 바로 돌려 보려면 HTML 탭이나 직접 해보기를 쓰세요.

버튼을 누르면 이 예제의 코드가 StackBlitz나 CodeSandbox로 전송돼요. 누르기 전에는 아무것도 보내지 않아요.

index.html
<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>
main.js
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));
example.js
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);
  },
};

Module files for a project with a bundler such as Vite. To run it with no setup, use the HTML tab or Try it.

When you click, the example code is sent to StackBlitz or CodeSandbox. Nothing is sent before you click.

index.html
<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>
main.js
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));
example.js
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);
  },
};