고정된 머리글과 줄 번호Fixed header and row numbers
줄을 스크롤해도 머리글은 맨 위에 그대로 있고, 줄 번호 컬럼은 화면에 보이는 순서를 세요. 그래서 정렬하거나 필터를 걸면 줄 번호가 다시 1번부터 시작해요. 줄 번호는 설정으로 켜고 끌 수 있어요.The header stays on top while the rows scroll, and the row number column counts the lines as shown, so sorting or filtering restarts at 1. Row numbers can be turned on and off with a setting.
코드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="numbers">
<option value="on" selected>켬 (기본)</option>
<option value="off">끔</option>
</select>
<button type="button" id="middle">중간으로 가기</button>
<button type="button" id="sortSalary">월급 큰 순</button>
<button type="button" id="onlyDesign">디자인팀만 보기</button>
<button type="button" id="reset">정렬·필터 풀기</button>
</div>
<div id="grid" style="height: 360px"></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('numbers').addEventListener('change', (event) => actions.numbers(api, event.target.value));
document.getElementById('middle').addEventListener('click', () => actions.middle(api));
document.getElementById('sortSalary').addEventListener('click', () => actions.sortSalary(api));
document.getElementById('onlyDesign').addEventListener('click', () => actions.onlyDesign(api));
document.getElementById('reset').addEventListener('click', () => actions.reset(api));const names = ['김민준', '이서연', '박지호', '최유나', '정도윤', '한소희'];
const depts = ['개발팀', '디자인팀', '영업팀', '인사팀'];
// 줄이 스크롤돼도 머리글은 맨 위에 그대로 있어요. 줄 번호 컬럼은 '화면에 보이는 순서'를 세기 때문에
// 정렬하거나 필터를 걸면 다시 1번부터 시작해요.
export const options = {
columns: [
{ id: 'name', title: '이름', width: 150 },
{ id: 'dept', title: '부서', width: 130 },
{
id: 'salary',
title: '월급(만원)',
kind: 'number',
width: 130,
align: 'end',
formatValue: (value) => Number(value).toLocaleString('ko-KR'),
},
],
rows: Array.from({ length: 200 }, (_, i) => ({
id: i + 1,
name: `${names[i % 6]} ${Math.floor(i / 6) + 1}`,
dept: depts[i % 4],
salary: 300 + ((i * 79) % 500),
})),
rowKey: 'id',
showRowNumbers: true,
headerHeight: 40,
};
export const actions = {
numbers: (api, value) => api.setOptions({ showRowNumbers: value !== 'off' }),
sortSalary: (api) => {
api.setSortModel([{ columnId: 'salary', direction: 'desc' }]);
api.scrollToIndex(0); // 정렬하면 맨 위로 올라가서 1번부터 보여 줘요
},
onlyDesign: (api) => api.setFilterModel({
match: 'all',
items: [{ columnId: 'dept', operator: 'equals', value: '디자인팀' }],
}),
reset: (api) => {
api.setSortModel([]);
api.setFilterModel(null);
api.scrollToIndex(0);
},
middle: (api) => api.scrollToIndex(Math.min(100, api.getVisibleRowCount() - 1)),
};<!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="numbers">
<option value="on" selected>켬 (기본)</option>
<option value="off">끔</option>
</select>
<button type="button" id="middle">중간으로 가기</button>
<button type="button" id="sortSalary">월급 큰 순</button>
<button type="button" id="onlyDesign">디자인팀만 보기</button>
<button type="button" id="reset">정렬·필터 풀기</button>
</div>
<div id="grid" style="height: 360px"></div>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script>
const names = ['김민준', '이서연', '박지호', '최유나', '정도윤', '한소희'];
const depts = ['개발팀', '디자인팀', '영업팀', '인사팀'];
// 줄이 스크롤돼도 머리글은 맨 위에 그대로 있어요. 줄 번호 컬럼은 '화면에 보이는 순서'를 세기 때문에
// 정렬하거나 필터를 걸면 다시 1번부터 시작해요.
const options = {
columns: [
{ id: 'name', title: '이름', width: 150 },
{ id: 'dept', title: '부서', width: 130 },
{
id: 'salary',
title: '월급(만원)',
kind: 'number',
width: 130,
align: 'end',
formatValue: (value) => Number(value).toLocaleString('ko-KR'),
},
],
rows: Array.from({ length: 200 }, (_, i) => ({
id: i + 1,
name: `${names[i % 6]} ${Math.floor(i / 6) + 1}`,
dept: depts[i % 4],
salary: 300 + ((i * 79) % 500),
})),
rowKey: 'id',
showRowNumbers: true,
headerHeight: 40,
};
const actions = {
numbers: (api, value) => api.setOptions({ showRowNumbers: value !== 'off' }),
sortSalary: (api) => {
api.setSortModel([{ columnId: 'salary', direction: 'desc' }]);
api.scrollToIndex(0); // 정렬하면 맨 위로 올라가서 1번부터 보여 줘요
},
onlyDesign: (api) => api.setFilterModel({
match: 'all',
items: [{ columnId: 'dept', operator: 'equals', value: '디자인팀' }],
}),
reset: (api) => {
api.setSortModel([]);
api.setFilterModel(null);
api.scrollToIndex(0);
},
middle: (api) => api.scrollToIndex(Math.min(100, api.getVisibleRowCount() - 1)),
};
options.ariaLabel = "고정된 머리글과 줄 번호";
const api = MaxGrid.createGrid(document.getElementById('grid'), options);
document.getElementById('numbers').addEventListener('change', (event) => actions.numbers(api, event.target.value));
document.getElementById('middle').addEventListener('click', () => actions.middle(api));
document.getElementById('sortSalary').addEventListener('click', () => actions.sortSalary(api));
document.getElementById('onlyDesign').addEventListener('click', () => actions.onlyDesign(api));
document.getElementById('reset').addEventListener('click', () => actions.reset(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.numbers(api, event.target.value)}
>
<option value="on">켬 (기본)</option>
<option value="off">끔</option>
</select>
<button
type="button"
disabled={!api}
onClick={() => api && actions.middle(api)}
>중간으로 가기</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.sortSalary(api)}
>월급 큰 순</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.onlyDesign(api)}
>디자인팀만 보기</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.reset(api)}
>정렬·필터 풀기</button>
</div>
<Grid style={{ height: 360 }} ref={gridRef} options={options} />
</>
);
}import type { GridApi, GridOptions } from '@maxgrid/react';
export interface Row {
id: number;
name: string;
dept: string;
salary: number;
}
const names = ['김민준', '이서연', '박지호', '최유나', '정도윤', '한소희'];
const depts = ['개발팀', '디자인팀', '영업팀', '인사팀'];
// 줄이 스크롤돼도 머리글은 맨 위에 그대로 있어요. 줄 번호 컬럼은 '화면에 보이는 순서'를 세기 때문에
// 정렬하거나 필터를 걸면 다시 1번부터 시작해요.
export const options: GridOptions<Row> = {
columns: [
{ id: 'name', title: '이름', width: 150 },
{ id: 'dept', title: '부서', width: 130 },
{
id: 'salary',
title: '월급(만원)',
kind: 'number',
width: 130,
align: 'end',
formatValue: (value) => Number(value).toLocaleString('ko-KR'),
},
],
rows: Array.from({ length: 200 }, (_, i) => ({
id: i + 1,
name: `${names[i % 6]} ${Math.floor(i / 6) + 1}`,
dept: depts[i % 4] as string,
salary: 300 + ((i * 79) % 500),
})),
rowKey: 'id',
showRowNumbers: true,
headerHeight: 40,
};
export const actions = {
numbers: (api: GridApi<Row>, value?: string) =>
api.setOptions({ showRowNumbers: value !== 'off' }),
sortSalary: (api: GridApi<Row>) => {
api.setSortModel([{ columnId: 'salary', direction: 'desc' }]);
api.scrollToIndex(0); // 정렬하면 맨 위로 올라가서 1번부터 보여 줘요
},
onlyDesign: (api: GridApi<Row>) =>
api.setFilterModel({
match: 'all',
items: [{ columnId: 'dept', operator: 'equals', value: '디자인팀' }],
}),
reset: (api: GridApi<Row>) => {
api.setSortModel([]);
api.setFilterModel(null);
api.scrollToIndex(0);
},
middle: (api: GridApi<Row>) => api.scrollToIndex(Math.min(100, api.getVisibleRowCount() - 1)),
};버튼을 누르면 이 예제의 코드가 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.numbers(api, ($event.target as HTMLSelectElement).value)"
>
<option value="on" selected>켬 (기본)</option>
<option value="off">끔</option>
</select>
<button type="button" :disabled="!api" @click="api && actions.middle(api)">중간으로 가기</button>
<button
type="button"
:disabled="!api"
@click="api && actions.sortSalary(api)"
>월급 큰 순</button>
<button
type="button"
:disabled="!api"
@click="api && actions.onlyDesign(api)"
>디자인팀만 보기</button>
<button type="button" :disabled="!api" @click="api && actions.reset(api)">정렬·필터 풀기</button>
</div>
<Grid style="height: 360px" :options="options" @ready="onReady" />
</template>import type { GridApi, GridOptions } from '@maxgrid/vue';
export interface Row {
id: number;
name: string;
dept: string;
salary: number;
}
const names = ['김민준', '이서연', '박지호', '최유나', '정도윤', '한소희'];
const depts = ['개발팀', '디자인팀', '영업팀', '인사팀'];
// 줄이 스크롤돼도 머리글은 맨 위에 그대로 있어요. 줄 번호 컬럼은 '화면에 보이는 순서'를 세기 때문에
// 정렬하거나 필터를 걸면 다시 1번부터 시작해요.
export const options: GridOptions<Row> = {
columns: [
{ id: 'name', title: '이름', width: 150 },
{ id: 'dept', title: '부서', width: 130 },
{
id: 'salary',
title: '월급(만원)',
kind: 'number',
width: 130,
align: 'end',
formatValue: (value) => Number(value).toLocaleString('ko-KR'),
},
],
rows: Array.from({ length: 200 }, (_, i) => ({
id: i + 1,
name: `${names[i % 6]} ${Math.floor(i / 6) + 1}`,
dept: depts[i % 4] as string,
salary: 300 + ((i * 79) % 500),
})),
rowKey: 'id',
showRowNumbers: true,
headerHeight: 40,
};
export const actions = {
numbers: (api: GridApi<Row>, value?: string) =>
api.setOptions({ showRowNumbers: value !== 'off' }),
sortSalary: (api: GridApi<Row>) => {
api.setSortModel([{ columnId: 'salary', direction: 'desc' }]);
api.scrollToIndex(0); // 정렬하면 맨 위로 올라가서 1번부터 보여 줘요
},
onlyDesign: (api: GridApi<Row>) =>
api.setFilterModel({
match: 'all',
items: [{ columnId: 'dept', operator: 'equals', value: '디자인팀' }],
}),
reset: (api: GridApi<Row>) => {
api.setSortModel([]);
api.setFilterModel(null);
api.scrollToIndex(0);
},
middle: (api: GridApi<Row>) => api.scrollToIndex(Math.min(100, api.getVisibleRowCount() - 1)),
};버튼을 누르면 이 예제의 코드가 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.numbers(api, $any($event.target).value)"
>
<option value="on" selected>켬 (기본)</option>
<option value="off">끔</option>
</select>
<button
type="button"
[disabled]="!api"
(click)="api && actions.middle(api)"
>중간으로 가기</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.sortSalary(api)"
>월급 큰 순</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.onlyDesign(api)"
>디자인팀만 보기</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.reset(api)"
>정렬·필터 풀기</button>
</div>
<mx-grid style="height: 360px" [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 { GridApi, GridOptions } from '@maxgrid/angular';
export interface Row {
id: number;
name: string;
dept: string;
salary: number;
}
const names = ['김민준', '이서연', '박지호', '최유나', '정도윤', '한소희'];
const depts = ['개발팀', '디자인팀', '영업팀', '인사팀'];
// 줄이 스크롤돼도 머리글은 맨 위에 그대로 있어요. 줄 번호 컬럼은 '화면에 보이는 순서'를 세기 때문에
// 정렬하거나 필터를 걸면 다시 1번부터 시작해요.
export const options: GridOptions<Row> = {
columns: [
{ id: 'name', title: '이름', width: 150 },
{ id: 'dept', title: '부서', width: 130 },
{
id: 'salary',
title: '월급(만원)',
kind: 'number',
width: 130,
align: 'end',
formatValue: (value) => Number(value).toLocaleString('ko-KR'),
},
],
rows: Array.from({ length: 200 }, (_, i) => ({
id: i + 1,
name: `${names[i % 6]} ${Math.floor(i / 6) + 1}`,
dept: depts[i % 4] as string,
salary: 300 + ((i * 79) % 500),
})),
rowKey: 'id',
showRowNumbers: true,
headerHeight: 40,
};
export const actions = {
numbers: (api: GridApi<Row>, value?: string) =>
api.setOptions({ showRowNumbers: value !== 'off' }),
sortSalary: (api: GridApi<Row>) => {
api.setSortModel([{ columnId: 'salary', direction: 'desc' }]);
api.scrollToIndex(0); // 정렬하면 맨 위로 올라가서 1번부터 보여 줘요
},
onlyDesign: (api: GridApi<Row>) =>
api.setFilterModel({
match: 'all',
items: [{ columnId: 'dept', operator: 'equals', value: '디자인팀' }],
}),
reset: (api: GridApi<Row>) => {
api.setSortModel([]);
api.setFilterModel(null);
api.scrollToIndex(0);
},
middle: (api: GridApi<Row>) => api.scrollToIndex(Math.min(100, api.getVisibleRowCount() - 1)),
};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="Row numbers" id="numbers">
<option value="on" selected>On (default)</option>
<option value="off">Off</option>
</select>
<button type="button" id="middle">Go to middle</button>
<button type="button" id="sortSalary">Salary high to low</button>
<button type="button" id="onlyDesign">Design team only</button>
<button type="button" id="reset">Clear sort and filter</button>
</div>
<div id="grid" style="height: 360px"></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('numbers').addEventListener('change', (event) => actions.numbers(api, event.target.value));
document.getElementById('middle').addEventListener('click', () => actions.middle(api));
document.getElementById('sortSalary').addEventListener('click', () => actions.sortSalary(api));
document.getElementById('onlyDesign').addEventListener('click', () => actions.onlyDesign(api));
document.getElementById('reset').addEventListener('click', () => actions.reset(api));const names = [
'Liam Carter',
'Emma Stone',
'Noah Reed',
'Olivia Hayes',
'Ethan Brooks',
'Ava Morgan',
];
const depts = ['Dev', 'Design', 'Sales', 'HR'];
// The header stays at the top while rows scroll. The row-number column counts the order as shown on screen,
// so it starts again from 1 after sorting or filtering.
export const options = {
columns: [
{ id: 'name', title: 'Name', width: 170 },
{ id: 'dept', title: 'Dept', width: 130 },
{
id: 'salary',
title: 'Monthly pay ($)',
kind: 'number',
width: 150,
align: 'end',
formatValue: (value) => Number(value).toLocaleString('en-US'),
},
],
rows: Array.from({ length: 200 }, (_, i) => ({
id: i + 1,
name: `${names[i % 6]} ${Math.floor(i / 6) + 1}`,
dept: depts[i % 4],
salary: 300 + ((i * 79) % 500),
})),
rowKey: 'id',
showRowNumbers: true,
headerHeight: 40,
};
export const actions = {
numbers: (api, value) => api.setOptions({ showRowNumbers: value !== 'off' }),
sortSalary: (api) => {
api.setSortModel([{ columnId: 'salary', direction: 'desc' }]);
api.scrollToIndex(0); // sorting jumps to the top so numbering shows from 1
},
onlyDesign: (api) => api.setFilterModel({
match: 'all',
items: [{ columnId: 'dept', operator: 'equals', value: 'Design' }],
}),
reset: (api) => {
api.setSortModel([]);
api.setFilterModel(null);
api.scrollToIndex(0);
},
middle: (api) => api.scrollToIndex(Math.min(100, api.getVisibleRowCount() - 1)),
};<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Fixed header and row numbers</title>
</head>
<body>
<div class="toolbar">
<select aria-label="Row numbers" id="numbers">
<option value="on" selected>On (default)</option>
<option value="off">Off</option>
</select>
<button type="button" id="middle">Go to middle</button>
<button type="button" id="sortSalary">Salary high to low</button>
<button type="button" id="onlyDesign">Design team only</button>
<button type="button" id="reset">Clear sort and filter</button>
</div>
<div id="grid" style="height: 360px"></div>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script>
const names = [
'Liam Carter',
'Emma Stone',
'Noah Reed',
'Olivia Hayes',
'Ethan Brooks',
'Ava Morgan',
];
const depts = ['Dev', 'Design', 'Sales', 'HR'];
// The header stays at the top while rows scroll. The row-number column counts the order as shown on screen,
// so it starts again from 1 after sorting or filtering.
const options = {
columns: [
{ id: 'name', title: 'Name', width: 170 },
{ id: 'dept', title: 'Dept', width: 130 },
{
id: 'salary',
title: 'Monthly pay ($)',
kind: 'number',
width: 150,
align: 'end',
formatValue: (value) => Number(value).toLocaleString('en-US'),
},
],
rows: Array.from({ length: 200 }, (_, i) => ({
id: i + 1,
name: `${names[i % 6]} ${Math.floor(i / 6) + 1}`,
dept: depts[i % 4],
salary: 300 + ((i * 79) % 500),
})),
rowKey: 'id',
showRowNumbers: true,
headerHeight: 40,
};
const actions = {
numbers: (api, value) => api.setOptions({ showRowNumbers: value !== 'off' }),
sortSalary: (api) => {
api.setSortModel([{ columnId: 'salary', direction: 'desc' }]);
api.scrollToIndex(0); // sorting jumps to the top so numbering shows from 1
},
onlyDesign: (api) => api.setFilterModel({
match: 'all',
items: [{ columnId: 'dept', operator: 'equals', value: 'Design' }],
}),
reset: (api) => {
api.setSortModel([]);
api.setFilterModel(null);
api.scrollToIndex(0);
},
middle: (api) => api.scrollToIndex(Math.min(100, api.getVisibleRowCount() - 1)),
};
options.ariaLabel = "Fixed header and row numbers";
const api = MaxGrid.createGrid(document.getElementById('grid'), options);
document.getElementById('numbers').addEventListener('change', (event) => actions.numbers(api, event.target.value));
document.getElementById('middle').addEventListener('click', () => actions.middle(api));
document.getElementById('sortSalary').addEventListener('click', () => actions.sortSalary(api));
document.getElementById('onlyDesign').addEventListener('click', () => actions.onlyDesign(api));
document.getElementById('reset').addEventListener('click', () => actions.reset(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="Row numbers"
disabled={!api}
onChange={(event) => api && actions.numbers(api, event.target.value)}
>
<option value="on">On (default)</option>
<option value="off">Off</option>
</select>
<button
type="button"
disabled={!api}
onClick={() => api && actions.middle(api)}
>Go to middle</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.sortSalary(api)}
>Salary high to low</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.onlyDesign(api)}
>Design team only</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.reset(api)}
>Clear sort and filter</button>
</div>
<Grid style={{ height: 360 }} ref={gridRef} options={options} />
</>
);
}import type { GridApi, GridOptions } from '@maxgrid/react';
export interface Row {
id: number;
name: string;
dept: string;
salary: number;
}
const names = [
'Liam Carter',
'Emma Stone',
'Noah Reed',
'Olivia Hayes',
'Ethan Brooks',
'Ava Morgan',
];
const depts = ['Dev', 'Design', 'Sales', 'HR'];
// The header stays at the top while rows scroll. The row-number column counts the order as shown on screen,
// so it starts again from 1 after sorting or filtering.
export const options: GridOptions<Row> = {
columns: [
{ id: 'name', title: 'Name', width: 170 },
{ id: 'dept', title: 'Dept', width: 130 },
{
id: 'salary',
title: 'Monthly pay ($)',
kind: 'number',
width: 150,
align: 'end',
formatValue: (value) => Number(value).toLocaleString('en-US'),
},
],
rows: Array.from({ length: 200 }, (_, i) => ({
id: i + 1,
name: `${names[i % 6]} ${Math.floor(i / 6) + 1}`,
dept: depts[i % 4] as string,
salary: 300 + ((i * 79) % 500),
})),
rowKey: 'id',
showRowNumbers: true,
headerHeight: 40,
};
export const actions = {
numbers: (api: GridApi<Row>, value?: string) =>
api.setOptions({ showRowNumbers: value !== 'off' }),
sortSalary: (api: GridApi<Row>) => {
api.setSortModel([{ columnId: 'salary', direction: 'desc' }]);
api.scrollToIndex(0); // sorting jumps to the top so numbering shows from 1
},
onlyDesign: (api: GridApi<Row>) =>
api.setFilterModel({
match: 'all',
items: [{ columnId: 'dept', operator: 'equals', value: 'Design' }],
}),
reset: (api: GridApi<Row>) => {
api.setSortModel([]);
api.setFilterModel(null);
api.scrollToIndex(0);
},
middle: (api: GridApi<Row>) => api.scrollToIndex(Math.min(100, api.getVisibleRowCount() - 1)),
};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="Row numbers"
:disabled="!api"
@change="api && actions.numbers(api, ($event.target as HTMLSelectElement).value)"
>
<option value="on" selected>On (default)</option>
<option value="off">Off</option>
</select>
<button type="button" :disabled="!api" @click="api && actions.middle(api)">Go to middle</button>
<button
type="button"
:disabled="!api"
@click="api && actions.sortSalary(api)"
>Salary high to low</button>
<button
type="button"
:disabled="!api"
@click="api && actions.onlyDesign(api)"
>Design team only</button>
<button type="button" :disabled="!api" @click="api && actions.reset(api)">Clear sort and filter</button>
</div>
<Grid style="height: 360px" :options="options" @ready="onReady" />
</template>import type { GridApi, GridOptions } from '@maxgrid/vue';
export interface Row {
id: number;
name: string;
dept: string;
salary: number;
}
const names = [
'Liam Carter',
'Emma Stone',
'Noah Reed',
'Olivia Hayes',
'Ethan Brooks',
'Ava Morgan',
];
const depts = ['Dev', 'Design', 'Sales', 'HR'];
// The header stays at the top while rows scroll. The row-number column counts the order as shown on screen,
// so it starts again from 1 after sorting or filtering.
export const options: GridOptions<Row> = {
columns: [
{ id: 'name', title: 'Name', width: 170 },
{ id: 'dept', title: 'Dept', width: 130 },
{
id: 'salary',
title: 'Monthly pay ($)',
kind: 'number',
width: 150,
align: 'end',
formatValue: (value) => Number(value).toLocaleString('en-US'),
},
],
rows: Array.from({ length: 200 }, (_, i) => ({
id: i + 1,
name: `${names[i % 6]} ${Math.floor(i / 6) + 1}`,
dept: depts[i % 4] as string,
salary: 300 + ((i * 79) % 500),
})),
rowKey: 'id',
showRowNumbers: true,
headerHeight: 40,
};
export const actions = {
numbers: (api: GridApi<Row>, value?: string) =>
api.setOptions({ showRowNumbers: value !== 'off' }),
sortSalary: (api: GridApi<Row>) => {
api.setSortModel([{ columnId: 'salary', direction: 'desc' }]);
api.scrollToIndex(0); // sorting jumps to the top so numbering shows from 1
},
onlyDesign: (api: GridApi<Row>) =>
api.setFilterModel({
match: 'all',
items: [{ columnId: 'dept', operator: 'equals', value: 'Design' }],
}),
reset: (api: GridApi<Row>) => {
api.setSortModel([]);
api.setFilterModel(null);
api.scrollToIndex(0);
},
middle: (api: GridApi<Row>) => api.scrollToIndex(Math.min(100, api.getVisibleRowCount() - 1)),
};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="Row numbers"
[disabled]="!api"
(change)="api && actions.numbers(api, $any($event.target).value)"
>
<option value="on" selected>On (default)</option>
<option value="off">Off</option>
</select>
<button
type="button"
[disabled]="!api"
(click)="api && actions.middle(api)"
>Go to middle</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.sortSalary(api)"
>Salary high to low</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.onlyDesign(api)"
>Design team only</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.reset(api)"
>Clear sort and filter</button>
</div>
<mx-grid style="height: 360px" [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 { GridApi, GridOptions } from '@maxgrid/angular';
export interface Row {
id: number;
name: string;
dept: string;
salary: number;
}
const names = [
'Liam Carter',
'Emma Stone',
'Noah Reed',
'Olivia Hayes',
'Ethan Brooks',
'Ava Morgan',
];
const depts = ['Dev', 'Design', 'Sales', 'HR'];
// The header stays at the top while rows scroll. The row-number column counts the order as shown on screen,
// so it starts again from 1 after sorting or filtering.
export const options: GridOptions<Row> = {
columns: [
{ id: 'name', title: 'Name', width: 170 },
{ id: 'dept', title: 'Dept', width: 130 },
{
id: 'salary',
title: 'Monthly pay ($)',
kind: 'number',
width: 150,
align: 'end',
formatValue: (value) => Number(value).toLocaleString('en-US'),
},
],
rows: Array.from({ length: 200 }, (_, i) => ({
id: i + 1,
name: `${names[i % 6]} ${Math.floor(i / 6) + 1}`,
dept: depts[i % 4] as string,
salary: 300 + ((i * 79) % 500),
})),
rowKey: 'id',
showRowNumbers: true,
headerHeight: 40,
};
export const actions = {
numbers: (api: GridApi<Row>, value?: string) =>
api.setOptions({ showRowNumbers: value !== 'off' }),
sortSalary: (api: GridApi<Row>) => {
api.setSortModel([{ columnId: 'salary', direction: 'desc' }]);
api.scrollToIndex(0); // sorting jumps to the top so numbering shows from 1
},
onlyDesign: (api: GridApi<Row>) =>
api.setFilterModel({
match: 'all',
items: [{ columnId: 'dept', operator: 'equals', value: 'Design' }],
}),
reset: (api: GridApi<Row>) => {
api.setSortModel([]);
api.setFilterModel(null);
api.scrollToIndex(0);
},
middle: (api: GridApi<Row>) => api.scrollToIndex(Math.min(100, api.getVisibleRowCount() - 1)),
};