새 행에 줄 순서 번호 받기Get an order number for a new row
nextOrderValue로 맨 앞·맨 뒤·특정 행 뒤에 넣을 새 행의 번호를 받아요. 받은 번호로 addRows의 index 자리에 넣으면 번호 순서와 화면 순서가 맞아요.nextOrderValue returns the number for a new row at the start, at the end or after a given row. Add the row with addRows at the matching index and the number order matches the screen order.
코드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="addStart">맨 앞에 추가</button>
<button type="button" id="addEnd">맨 뒤에 추가</button>
<button type="button" id="addAfterSecond">둘째 행 뒤에 추가</button>
</div>
<div id="grid" style="height: 360px"></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('addStart').addEventListener('click', () => actions.addStart(api));
document.getElementById('addEnd').addEventListener('click', () => actions.addEnd(api));
document.getElementById('addAfterSecond').addEventListener('click', () => actions.addAfterSecond(api));const tasks = ['요구사항 정리', '화면 설계', '데이터 모델', 'API 구현', '테스트 작성'];
export const options = {
columns: [
{ id: 'seq', title: '순서 번호', width: 90, align: 'end' },
{ id: 'task', title: '할 일', width: 200 },
],
rows: tasks.map((task, i) => ({ id: i + 1, seq: (i + 1) * 10, task })),
rowKey: 'id',
orderIndex: { field: 'seq' },
};
let say = () => { };
let nextId = 6;
export function setup(api, log) {
say = log;
nextId = 6;
log({
ko: '새 행의 번호는 nextOrderValue로 받아요. 넣을 자리의 앞뒤 번호 사이 값이에요.',
en: 'The number for a new row comes from nextOrderValue: a value between the neighbors of its spot.',
});
return () => { };
}
function add(api, seq, index) {
const id = nextId++;
api.addRows([{ id, seq, task: `새 업무 ${id}` }], { index });
say({ ko: `${id}번 행을 추가했어요: 번호 ${seq}`, en: `Added row ${id} with number ${seq}` });
}
export const actions = {
addStart: (api) => add(api, api.nextOrderValue('start'), 0),
addEnd: (api) => add(api, api.nextOrderValue('end'), api.getRowCount()),
addAfterSecond: (api) => {
const second = api.getRows()[1];
add(api, api.nextOrderValue({ after: second.id }), 2);
},
};<!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="addStart">맨 앞에 추가</button>
<button type="button" id="addEnd">맨 뒤에 추가</button>
<button type="button" id="addAfterSecond">둘째 행 뒤에 추가</button>
</div>
<div id="grid" style="height: 360px"></div>
<ul id="log" aria-live="polite"></ul>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script>
const tasks = ['요구사항 정리', '화면 설계', '데이터 모델', 'API 구현', '테스트 작성'];
const options = {
columns: [
{ id: 'seq', title: '순서 번호', width: 90, align: 'end' },
{ id: 'task', title: '할 일', width: 200 },
],
rows: tasks.map((task, i) => ({ id: i + 1, seq: (i + 1) * 10, task })),
rowKey: 'id',
orderIndex: { field: 'seq' },
};
let say = () => { };
let nextId = 6;
function setup(api, log) {
say = log;
nextId = 6;
log({
ko: '새 행의 번호는 nextOrderValue로 받아요. 넣을 자리의 앞뒤 번호 사이 값이에요.',
en: 'The number for a new row comes from nextOrderValue: a value between the neighbors of its spot.',
});
return () => { };
}
function add(api, seq, index) {
const id = nextId++;
api.addRows([{ id, seq, task: `새 업무 ${id}` }], { index });
say({ ko: `${id}번 행을 추가했어요: 번호 ${seq}`, en: `Added row ${id} with number ${seq}` });
}
const actions = {
addStart: (api) => add(api, api.nextOrderValue('start'), 0),
addEnd: (api) => add(api, api.nextOrderValue('end'), api.getRowCount()),
addAfterSecond: (api) => {
const second = api.getRows()[1];
add(api, api.nextOrderValue({ after: second.id }), 2);
},
};
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('addStart').addEventListener('click', () => actions.addStart(api));
document.getElementById('addEnd').addEventListener('click', () => actions.addEnd(api));
document.getElementById('addAfterSecond').addEventListener('click', () => actions.addAfterSecond(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.addStart(api)}
>맨 앞에 추가</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.addEnd(api)}
>맨 뒤에 추가</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.addAfterSecond(api)}
>둘째 행 뒤에 추가</button>
</div>
<Grid style={{ height: 360 }} ref={gridRef} options={options} />
</>
);
}import type { GridApi, GridOptions } from '@maxgrid/react';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
seq: number;
task: string;
}
const tasks = ['요구사항 정리', '화면 설계', '데이터 모델', 'API 구현', '테스트 작성'];
export const options: GridOptions<Row> = {
columns: [
{ id: 'seq', title: '순서 번호', width: 90, align: 'end' },
{ id: 'task', title: '할 일', width: 200 },
],
rows: tasks.map((task, i) => ({ id: i + 1, seq: (i + 1) * 10, task })),
rowKey: 'id',
orderIndex: { field: 'seq' },
};
let say: (message: LogText) => void = () => {};
let nextId = 6;
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
nextId = 6;
log({
ko: '새 행의 번호는 nextOrderValue로 받아요. 넣을 자리의 앞뒤 번호 사이 값이에요.',
en: 'The number for a new row comes from nextOrderValue: a value between the neighbors of its spot.',
});
return () => {};
}
function add(api: GridApi<Row>, seq: number, index: number): void {
const id = nextId++;
api.addRows([{ id, seq, task: `새 업무 ${id}` }], { index });
say({ ko: `${id}번 행을 추가했어요: 번호 ${seq}`, en: `Added row ${id} with number ${seq}` });
}
export const actions = {
addStart: (api: GridApi<Row>) => add(api, api.nextOrderValue('start'), 0),
addEnd: (api: GridApi<Row>) => add(api, api.nextOrderValue('end'), api.getRowCount()),
addAfterSecond: (api: GridApi<Row>) => {
const second = api.getRows()[1] as Row;
add(api, api.nextOrderValue({ after: second.id }), 2);
},
};버튼을 누르면 이 예제의 코드가 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.addStart(api)"
>맨 앞에 추가</button>
<button type="button" :disabled="!api" @click="api && actions.addEnd(api)">맨 뒤에 추가</button>
<button
type="button"
:disabled="!api"
@click="api && actions.addAfterSecond(api)"
>둘째 행 뒤에 추가</button>
</div>
<Grid style="height: 360px" :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;
seq: number;
task: string;
}
const tasks = ['요구사항 정리', '화면 설계', '데이터 모델', 'API 구현', '테스트 작성'];
export const options: GridOptions<Row> = {
columns: [
{ id: 'seq', title: '순서 번호', width: 90, align: 'end' },
{ id: 'task', title: '할 일', width: 200 },
],
rows: tasks.map((task, i) => ({ id: i + 1, seq: (i + 1) * 10, task })),
rowKey: 'id',
orderIndex: { field: 'seq' },
};
let say: (message: LogText) => void = () => {};
let nextId = 6;
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
nextId = 6;
log({
ko: '새 행의 번호는 nextOrderValue로 받아요. 넣을 자리의 앞뒤 번호 사이 값이에요.',
en: 'The number for a new row comes from nextOrderValue: a value between the neighbors of its spot.',
});
return () => {};
}
function add(api: GridApi<Row>, seq: number, index: number): void {
const id = nextId++;
api.addRows([{ id, seq, task: `새 업무 ${id}` }], { index });
say({ ko: `${id}번 행을 추가했어요: 번호 ${seq}`, en: `Added row ${id} with number ${seq}` });
}
export const actions = {
addStart: (api: GridApi<Row>) => add(api, api.nextOrderValue('start'), 0),
addEnd: (api: GridApi<Row>) => add(api, api.nextOrderValue('end'), api.getRowCount()),
addAfterSecond: (api: GridApi<Row>) => {
const second = api.getRows()[1] as Row;
add(api, api.nextOrderValue({ after: second.id }), 2);
},
};버튼을 누르면 이 예제의 코드가 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.addStart(api)"
>맨 앞에 추가</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.addEnd(api)"
>맨 뒤에 추가</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.addAfterSecond(api)"
>둘째 행 뒤에 추가</button>
</div>
<mx-grid style="height: 360px" [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;
seq: number;
task: string;
}
const tasks = ['요구사항 정리', '화면 설계', '데이터 모델', 'API 구현', '테스트 작성'];
export const options: GridOptions<Row> = {
columns: [
{ id: 'seq', title: '순서 번호', width: 90, align: 'end' },
{ id: 'task', title: '할 일', width: 200 },
],
rows: tasks.map((task, i) => ({ id: i + 1, seq: (i + 1) * 10, task })),
rowKey: 'id',
orderIndex: { field: 'seq' },
};
let say: (message: LogText) => void = () => {};
let nextId = 6;
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
nextId = 6;
log({
ko: '새 행의 번호는 nextOrderValue로 받아요. 넣을 자리의 앞뒤 번호 사이 값이에요.',
en: 'The number for a new row comes from nextOrderValue: a value between the neighbors of its spot.',
});
return () => {};
}
function add(api: GridApi<Row>, seq: number, index: number): void {
const id = nextId++;
api.addRows([{ id, seq, task: `새 업무 ${id}` }], { index });
say({ ko: `${id}번 행을 추가했어요: 번호 ${seq}`, en: `Added row ${id} with number ${seq}` });
}
export const actions = {
addStart: (api: GridApi<Row>) => add(api, api.nextOrderValue('start'), 0),
addEnd: (api: GridApi<Row>) => add(api, api.nextOrderValue('end'), api.getRowCount()),
addAfterSecond: (api: GridApi<Row>) => {
const second = api.getRows()[1] as Row;
add(api, api.nextOrderValue({ after: second.id }), 2);
},
};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="addStart">Add at start</button>
<button type="button" id="addEnd">Add at end</button>
<button type="button" id="addAfterSecond">Add after second row</button>
</div>
<div id="grid" style="height: 360px"></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('addStart').addEventListener('click', () => actions.addStart(api));
document.getElementById('addEnd').addEventListener('click', () => actions.addEnd(api));
document.getElementById('addAfterSecond').addEventListener('click', () => actions.addAfterSecond(api));const tasks = ['Gather requirements', 'Design screens', 'Data model', 'Build API', 'Write tests'];
export const options = {
columns: [
{ id: 'seq', title: 'Order', width: 80, align: 'end' },
{ id: 'task', title: 'Task', width: 200 },
],
rows: tasks.map((task, i) => ({ id: i + 1, seq: (i + 1) * 10, task })),
rowKey: 'id',
orderIndex: { field: 'seq' },
};
let say = () => { };
let nextId = 6;
export function setup(api, log) {
say = log;
nextId = 6;
log('The number for a new row comes from nextOrderValue: a value between the neighbors of its spot.');
return () => { };
}
function add(api, seq, index) {
const id = nextId++;
api.addRows([{ id, seq, task: `New task ${id}` }], { index });
say(`Added row ${id} with number ${seq}`);
}
export const actions = {
addStart: (api) => add(api, api.nextOrderValue('start'), 0),
addEnd: (api) => add(api, api.nextOrderValue('end'), api.getRowCount()),
addAfterSecond: (api) => {
const second = api.getRows()[1];
add(api, api.nextOrderValue({ after: second.id }), 2);
},
};<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Get an order number for a new row</title>
</head>
<body>
<div class="toolbar">
<button type="button" id="addStart">Add at start</button>
<button type="button" id="addEnd">Add at end</button>
<button type="button" id="addAfterSecond">Add after second row</button>
</div>
<div id="grid" style="height: 360px"></div>
<ul id="log" aria-live="polite"></ul>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script>
const tasks = ['Gather requirements', 'Design screens', 'Data model', 'Build API', 'Write tests'];
const options = {
columns: [
{ id: 'seq', title: 'Order', width: 80, align: 'end' },
{ id: 'task', title: 'Task', width: 200 },
],
rows: tasks.map((task, i) => ({ id: i + 1, seq: (i + 1) * 10, task })),
rowKey: 'id',
orderIndex: { field: 'seq' },
};
let say = () => { };
let nextId = 6;
function setup(api, log) {
say = log;
nextId = 6;
log('The number for a new row comes from nextOrderValue: a value between the neighbors of its spot.');
return () => { };
}
function add(api, seq, index) {
const id = nextId++;
api.addRows([{ id, seq, task: `New task ${id}` }], { index });
say(`Added row ${id} with number ${seq}`);
}
const actions = {
addStart: (api) => add(api, api.nextOrderValue('start'), 0),
addEnd: (api) => add(api, api.nextOrderValue('end'), api.getRowCount()),
addAfterSecond: (api) => {
const second = api.getRows()[1];
add(api, api.nextOrderValue({ after: second.id }), 2);
},
};
options.ariaLabel = "Get an order number for a new row";
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('addStart').addEventListener('click', () => actions.addStart(api));
document.getElementById('addEnd').addEventListener('click', () => actions.addEnd(api));
document.getElementById('addAfterSecond').addEventListener('click', () => actions.addAfterSecond(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.addStart(api)}
>Add at start</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.addEnd(api)}
>Add at end</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.addAfterSecond(api)}
>Add after second row</button>
</div>
<Grid style={{ height: 360 }} ref={gridRef} options={options} />
</>
);
}import type { GridApi, GridOptions } from '@maxgrid/react';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
seq: number;
task: string;
}
const tasks = ['Gather requirements', 'Design screens', 'Data model', 'Build API', 'Write tests'];
export const options: GridOptions<Row> = {
columns: [
{ id: 'seq', title: 'Order', width: 80, align: 'end' },
{ id: 'task', title: 'Task', width: 200 },
],
rows: tasks.map((task, i) => ({ id: i + 1, seq: (i + 1) * 10, task })),
rowKey: 'id',
orderIndex: { field: 'seq' },
};
let say: (message: LogText) => void = () => {};
let nextId = 6;
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
nextId = 6;
log(
'The number for a new row comes from nextOrderValue: a value between the neighbors of its spot.',
);
return () => {};
}
function add(api: GridApi<Row>, seq: number, index: number): void {
const id = nextId++;
api.addRows([{ id, seq, task: `New task ${id}` }], { index });
say(`Added row ${id} with number ${seq}`);
}
export const actions = {
addStart: (api: GridApi<Row>) => add(api, api.nextOrderValue('start'), 0),
addEnd: (api: GridApi<Row>) => add(api, api.nextOrderValue('end'), api.getRowCount()),
addAfterSecond: (api: GridApi<Row>) => {
const second = api.getRows()[1] as Row;
add(api, api.nextOrderValue({ after: second.id }), 2);
},
};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.addStart(api)"
>Add at start</button>
<button type="button" :disabled="!api" @click="api && actions.addEnd(api)">Add at end</button>
<button
type="button"
:disabled="!api"
@click="api && actions.addAfterSecond(api)"
>Add after second row</button>
</div>
<Grid style="height: 360px" :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;
seq: number;
task: string;
}
const tasks = ['Gather requirements', 'Design screens', 'Data model', 'Build API', 'Write tests'];
export const options: GridOptions<Row> = {
columns: [
{ id: 'seq', title: 'Order', width: 80, align: 'end' },
{ id: 'task', title: 'Task', width: 200 },
],
rows: tasks.map((task, i) => ({ id: i + 1, seq: (i + 1) * 10, task })),
rowKey: 'id',
orderIndex: { field: 'seq' },
};
let say: (message: LogText) => void = () => {};
let nextId = 6;
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
nextId = 6;
log(
'The number for a new row comes from nextOrderValue: a value between the neighbors of its spot.',
);
return () => {};
}
function add(api: GridApi<Row>, seq: number, index: number): void {
const id = nextId++;
api.addRows([{ id, seq, task: `New task ${id}` }], { index });
say(`Added row ${id} with number ${seq}`);
}
export const actions = {
addStart: (api: GridApi<Row>) => add(api, api.nextOrderValue('start'), 0),
addEnd: (api: GridApi<Row>) => add(api, api.nextOrderValue('end'), api.getRowCount()),
addAfterSecond: (api: GridApi<Row>) => {
const second = api.getRows()[1] as Row;
add(api, api.nextOrderValue({ after: second.id }), 2);
},
};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.addStart(api)"
>Add at start</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.addEnd(api)"
>Add at end</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.addAfterSecond(api)"
>Add after second row</button>
</div>
<mx-grid style="height: 360px" [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;
seq: number;
task: string;
}
const tasks = ['Gather requirements', 'Design screens', 'Data model', 'Build API', 'Write tests'];
export const options: GridOptions<Row> = {
columns: [
{ id: 'seq', title: 'Order', width: 80, align: 'end' },
{ id: 'task', title: 'Task', width: 200 },
],
rows: tasks.map((task, i) => ({ id: i + 1, seq: (i + 1) * 10, task })),
rowKey: 'id',
orderIndex: { field: 'seq' },
};
let say: (message: LogText) => void = () => {};
let nextId = 6;
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
nextId = 6;
log(
'The number for a new row comes from nextOrderValue: a value between the neighbors of its spot.',
);
return () => {};
}
function add(api: GridApi<Row>, seq: number, index: number): void {
const id = nextId++;
api.addRows([{ id, seq, task: `New task ${id}` }], { index });
say(`Added row ${id} with number ${seq}`);
}
export const actions = {
addStart: (api: GridApi<Row>) => add(api, api.nextOrderValue('start'), 0),
addEnd: (api: GridApi<Row>) => add(api, api.nextOrderValue('end'), api.getRowCount()),
addAfterSecond: (api: GridApi<Row>) => {
const second = api.getRows()[1] as Row;
add(api, api.nextOrderValue({ after: second.id }), 2);
},
};