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

다음·이전 칸으로 이동Move to the next and previous cell

findNext()·findPrev()는 활성 칸을 줄 순서(왼쪽에서 오른쪽, 위에서 아래)로 옮기고 그 칸에 포커스를 두며 화면으로 스크롤해요. 끝에서 처음으로 돌아가요. 정렬·필터·행이 바뀌면 한 틱에 한 번 다시 찾고 가장 가까운 칸을 활성으로 둬요. findChanged 이벤트가 { text, active, count }를 알려요.findNext() and findPrev() move the active cell in row order (left to right, top to bottom), focus it and scroll it into view, wrapping at the ends. After a sort, filter or row change the find is recomputed once per tick and the nearest cell stays active. The findChanged event reports { text, active, count }.

활용Intermediate
직접 써 보기Live preview다음·이전 칸으로 이동Move to the next and previous cell

코드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">
    <input type="text" aria-label="찾기" placeholder="기본값: 서울" id="search" />
    <button type="button" id="next">다음</button>
    <button type="button" id="prev">이전</button>
    <button type="button" id="sort">이름 내림차순 정렬</button>
    <button type="button" id="clear">지우기</button>
  </div>
  <div id="grid" style="height: 330px"></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('search').addEventListener('input', (event) => actions.search(api, event.target.value));
document.getElementById('next').addEventListener('click', () => actions.next(api));
document.getElementById('prev').addEventListener('click', () => actions.prev(api));
document.getElementById('sort').addEventListener('click', () => actions.sort(api));
document.getElementById('clear').addEventListener('click', () => actions.clear(api));
example.js
const rows = [
  { id: 1, name: '김하늘', city: '서울', dept: 'dev', memo: '김 팀장님과 면담' },
  { id: 2, name: '이도윤', city: '부산', dept: 'ops', memo: '' },
  { id: 3, name: '박서연', city: '서울', dept: 'dev', memo: '서울 출장 예정' },
  { id: 4, name: '김해린', city: '김해', dept: 'ops', memo: 'Kim 팀 합류' },
  { id: 5, name: '최지우', city: '대전', dept: 'dev', memo: '' },
  { id: 6, name: '정민준', city: '서울', dept: 'ops', memo: '김밥 주문 담당' },
  { id: 7, name: '강서윤', city: '광주', dept: 'dev', memo: '서울 본사 파견' },
  { id: 8, name: '조현우', city: '부산', dept: 'ops', memo: '' },
];
// findNext·findPrev는 활성 칸을 옮기고 그 칸에 포커스를 두며 화면으로 스크롤해요. 끝에서 처음으로 돌아가요.
export const options = {
  columns: [
    { id: 'name', title: '이름', width: 100 },
    { id: 'city', title: '도시', width: 90 },
    {
      id: 'dept',
      title: '부서',
      width: 90,
      kind: 'select',
      editorOptions: [
        { value: 'dev', label: '개발' },
        { value: 'ops', label: '운영' },
      ],
      optionLabel: (v) => (v === 'dev' ? '개발' : '운영'),
    },
    { id: 'memo', title: '메모', width: 200 },
  ],
  rows,
  rowKey: 'id',
};
export function setup(api, log) {
  api.find('서울');
  log({
    ko: '"서울"을 찾아 두었어요. 다음·이전 버튼으로 칸을 옮겨 보세요.',
    en: '"서울" is already found. Use the next and previous buttons to move between cells.',
  });
  return api.on('findChanged', (e) => log({ ko: `${e.count}칸 중 ${e.active + 1}번째`, en: `${e.active + 1} of ${e.count}` }));
}
export const actions = {
  search: (api, value) => void api.find((value ?? '').trim()),
  next: (api) => void api.findNext(),
  prev: (api) => void api.findPrev(),
  clear: (api) => api.clearFind(),
  sort: (api) => {
    api.setSortModel([{ columnId: 'name', direction: 'desc' }]);
  },
};

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">
    <input
      type="text"
      aria-label="Find"
      placeholder="Default: Austin"
      id="search"
    />
    <button type="button" id="next">Next</button>
    <button type="button" id="prev">Previous</button>
    <button type="button" id="sort">Sort by name desc</button>
    <button type="button" id="clear">Clear</button>
  </div>
  <div id="grid" style="height: 330px"></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('search').addEventListener('input', (event) => actions.search(api, event.target.value));
document.getElementById('next').addEventListener('click', () => actions.next(api));
document.getElementById('prev').addEventListener('click', () => actions.prev(api));
document.getElementById('sort').addEventListener('click', () => actions.sort(api));
document.getElementById('clear').addEventListener('click', () => actions.clear(api));
example.js
const rows = [
  { id: 1, name: 'Emma Clark', city: 'Austin', dept: 'dev', memo: 'Meeting with team lead Clark' },
  { id: 2, name: 'Liam Carter', city: 'Denver', dept: 'ops', memo: '' },
  {
    id: 3,
    name: 'Olivia Stone',
    city: 'Austin',
    dept: 'dev',
    memo: 'Austin business trip planned',
  },
  { id: 4, name: 'Noah Clarke', city: 'Clarksville', dept: 'ops', memo: 'Kim joins the team' },
  { id: 5, name: 'Ava Brooks', city: 'Seattle', dept: 'dev', memo: '' },
  {
    id: 6,
    name: 'Ethan Hayes',
    city: 'Austin',
    dept: 'ops',
    memo: 'Handles the Clarkson lunch order',
  },
  { id: 7, name: 'Mia Foster', city: 'Portland', dept: 'dev', memo: 'Sent to the Austin HQ' },
  { id: 8, name: 'Lucas Reed', city: 'Denver', dept: 'ops', memo: '' },
];
// findNext and findPrev move the active cell, focus it and scroll it into view. They wrap from the end to the start.
export const options = {
  columns: [
    { id: 'name', title: 'Name', width: 100 },
    { id: 'city', title: 'City', width: 90 },
    {
      id: 'dept',
      title: 'Dept',
      width: 90,
      kind: 'select',
      editorOptions: [
        { value: 'dev', label: 'Development' },
        { value: 'ops', label: 'Operations' },
      ],
      optionLabel: (v) => (v === 'dev' ? 'Development' : 'Operations'),
    },
    { id: 'memo', title: 'Memo', width: 200 },
  ],
  rows,
  rowKey: 'id',
};
export function setup(api, log) {
  api.find('Austin');
  log('"Austin" is already found. Use the next and previous buttons to move between cells.');
  return api.on('findChanged', (e) => log(`${e.active + 1} of ${e.count}`));
}
export const actions = {
  search: (api, value) => void api.find((value ?? '').trim()),
  next: (api) => void api.findNext(),
  prev: (api) => void api.findPrev(),
  clear: (api) => api.clearFind(),
  sort: (api) => {
    api.setSortModel([{ columnId: 'name', direction: 'desc' }]);
  },
};