컬럼 기본값을 한 번에 정하기Set column defaults once
columnDefaults로 모든 컬럼에 같은 기본 정의를 깔고, 컬럼이 직접 적은 값만 따로 정해요. defaultColumnWidth로 폭을 안 적은 컬럼의 폭도 한 번에 정해요.columnDefaults lays one default definition under every column, and a column only states what differs. defaultColumnWidth sets the width of columns that give none.
코드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 id="grid" style="height: 260px"></div>
</div>
<script type="module" src="./main.js"></script>import { createGrid } from 'maxgrid';
import { options } from './example';
const api = createGrid(document.getElementById('grid'), options);const names = ['김민준', '이서연', '박도윤', '최하은', '정시우', '강지민'];
const teams = ['개발팀', '디자인팀', '영업팀'];
const cities = ['서울', '부산', '대전'];
// columnDefaults는 모든 컬럼에 먼저 깔리는 기본 정의예요. 컬럼이 직접 적은 값이 항상 이겨요(여기서는 '메모'만 폭을 직접 정했어요).
// defaultColumnWidth는 폭을 정하지 않은 컬럼의 폭이에요.
export const options = {
columnDefaults: {
align: 'center',
editable: true,
headerTooltip: '기본 정의로 가운데 정렬·편집 가능',
},
defaultColumnWidth: 110,
columns: [
{ id: 'name', title: '이름' },
{ id: 'team', title: '팀' },
{ id: 'city', title: '근무지' },
{ id: 'note', title: '메모', width: 220, align: 'start' },
],
rows: names.map((name, i) => ({
id: i + 1,
name,
team: teams[i % 3],
city: cities[i % 3],
note: i % 2 === 0 ? '' : '확인 필요',
})),
rowKey: 'id',
};<!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 id="grid" style="height: 260px"></div>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script>
const names = ['김민준', '이서연', '박도윤', '최하은', '정시우', '강지민'];
const teams = ['개발팀', '디자인팀', '영업팀'];
const cities = ['서울', '부산', '대전'];
// columnDefaults는 모든 컬럼에 먼저 깔리는 기본 정의예요. 컬럼이 직접 적은 값이 항상 이겨요(여기서는 '메모'만 폭을 직접 정했어요).
// defaultColumnWidth는 폭을 정하지 않은 컬럼의 폭이에요.
const options = {
columnDefaults: {
align: 'center',
editable: true,
headerTooltip: '기본 정의로 가운데 정렬·편집 가능',
},
defaultColumnWidth: 110,
columns: [
{ id: 'name', title: '이름' },
{ id: 'team', title: '팀' },
{ id: 'city', title: '근무지' },
{ id: 'note', title: '메모', width: 220, align: 'start' },
],
rows: names.map((name, i) => ({
id: i + 1,
name,
team: teams[i % 3],
city: cities[i % 3],
note: i % 2 === 0 ? '' : '확인 필요',
})),
rowKey: 'id',
};
options.ariaLabel = "컬럼 기본값을 한 번에 정하기";
const api = MaxGrid.createGrid(document.getElementById('grid'), options);
</script>
</body>
</html>버튼을 누르면 이 예제의 코드가 StackBlitz나 CodeSandbox로 전송돼요. 누르기 전에는 아무것도 보내지 않아요.
import { Grid } from '@maxgrid/react';
import { options, type Row } from './example';
export function ExampleGrid() {
return (
<>
<Grid style={{ height: 260 }} options={options} />
</>
);
}import type { GridOptions } from '@maxgrid/react';
export interface Row {
id: number;
name: string;
team: string;
city: string;
note: string;
}
const names = ['김민준', '이서연', '박도윤', '최하은', '정시우', '강지민'];
const teams = ['개발팀', '디자인팀', '영업팀'];
const cities = ['서울', '부산', '대전'];
// columnDefaults는 모든 컬럼에 먼저 깔리는 기본 정의예요. 컬럼이 직접 적은 값이 항상 이겨요(여기서는 '메모'만 폭을 직접 정했어요).
// defaultColumnWidth는 폭을 정하지 않은 컬럼의 폭이에요.
export const options: GridOptions<Row> = {
columnDefaults: {
align: 'center',
editable: true,
headerTooltip: '기본 정의로 가운데 정렬·편집 가능',
},
defaultColumnWidth: 110,
columns: [
{ id: 'name', title: '이름' },
{ id: 'team', title: '팀' },
{ id: 'city', title: '근무지' },
{ id: 'note', title: '메모', width: 220, align: 'start' },
],
rows: names.map((name, i) => ({
id: i + 1,
name,
team: teams[i % 3] as string,
city: cities[i % 3] as string,
note: i % 2 === 0 ? '' : '확인 필요',
})),
rowKey: 'id',
};버튼을 누르면 이 예제의 코드가 StackBlitz나 CodeSandbox로 전송돼요. 누르기 전에는 아무것도 보내지 않아요.
<script setup lang="ts">
import { Grid } from '@maxgrid/vue';
import { options, type Row } from './example';
</script>
<template>
<Grid style="height: 260px" :options="options" />
</template>import type { GridOptions } from '@maxgrid/vue';
export interface Row {
id: number;
name: string;
team: string;
city: string;
note: string;
}
const names = ['김민준', '이서연', '박도윤', '최하은', '정시우', '강지민'];
const teams = ['개발팀', '디자인팀', '영업팀'];
const cities = ['서울', '부산', '대전'];
// columnDefaults는 모든 컬럼에 먼저 깔리는 기본 정의예요. 컬럼이 직접 적은 값이 항상 이겨요(여기서는 '메모'만 폭을 직접 정했어요).
// defaultColumnWidth는 폭을 정하지 않은 컬럼의 폭이에요.
export const options: GridOptions<Row> = {
columnDefaults: {
align: 'center',
editable: true,
headerTooltip: '기본 정의로 가운데 정렬·편집 가능',
},
defaultColumnWidth: 110,
columns: [
{ id: 'name', title: '이름' },
{ id: 'team', title: '팀' },
{ id: 'city', title: '근무지' },
{ id: 'note', title: '메모', width: 220, align: 'start' },
],
rows: names.map((name, i) => ({
id: i + 1,
name,
team: teams[i % 3] as string,
city: cities[i % 3] as string,
note: i % 2 === 0 ? '' : '확인 필요',
})),
rowKey: 'id',
};버튼을 누르면 이 예제의 코드가 StackBlitz나 CodeSandbox로 전송돼요. 누르기 전에는 아무것도 보내지 않아요.
import { Component } from '@angular/core';
import { GridComponent } from '@maxgrid/angular';
import { options, type Row } from './example';
@Component({
selector: 'app-example-grid',
standalone: true,
imports: [GridComponent],
template: `
<mx-grid style="height: 260px" [options]="options" />
`,
})
export class ExampleGridComponent {
readonly options = options;
}import type { GridOptions } from '@maxgrid/angular';
export interface Row {
id: number;
name: string;
team: string;
city: string;
note: string;
}
const names = ['김민준', '이서연', '박도윤', '최하은', '정시우', '강지민'];
const teams = ['개발팀', '디자인팀', '영업팀'];
const cities = ['서울', '부산', '대전'];
// columnDefaults는 모든 컬럼에 먼저 깔리는 기본 정의예요. 컬럼이 직접 적은 값이 항상 이겨요(여기서는 '메모'만 폭을 직접 정했어요).
// defaultColumnWidth는 폭을 정하지 않은 컬럼의 폭이에요.
export const options: GridOptions<Row> = {
columnDefaults: {
align: 'center',
editable: true,
headerTooltip: '기본 정의로 가운데 정렬·편집 가능',
},
defaultColumnWidth: 110,
columns: [
{ id: 'name', title: '이름' },
{ id: 'team', title: '팀' },
{ id: 'city', title: '근무지' },
{ id: 'note', title: '메모', width: 220, align: 'start' },
],
rows: names.map((name, i) => ({
id: i + 1,
name,
team: teams[i % 3] as string,
city: cities[i % 3] as string,
note: i % 2 === 0 ? '' : '확인 필요',
})),
rowKey: 'id',
};When you click, the example code is sent to StackBlitz or CodeSandbox. Nothing is sent before you click.
<div id="app">
<div id="grid" style="height: 260px"></div>
</div>
<script type="module" src="./main.js"></script>import { createGrid } from 'maxgrid';
import { options } from './example';
const api = createGrid(document.getElementById('grid'), options);const names = ['Liam Carter', 'Emma Stone', 'Noah Hayes', 'Olivia Reed', 'Ethan Cole', 'Ava Lane'];
const teams = ['Dev', 'Design', 'Sales'];
const cities = ['Seattle', 'Boston', 'Denver'];
// columnDefaults is the default definition laid under every column. A value a column states itself always wins (here only 'Note' sets its own width).
// defaultColumnWidth is the width of columns that do not set one.
export const options = {
columnDefaults: {
align: 'center',
editable: true,
headerTooltip: 'Centered and editable by the default definition',
},
defaultColumnWidth: 110,
columns: [
{ id: 'name', title: 'Name' },
{ id: 'team', title: 'Team' },
{ id: 'city', title: 'City' },
{ id: 'note', title: 'Note', width: 220, align: 'start' },
],
rows: names.map((name, i) => ({
id: i + 1,
name,
team: teams[i % 3],
city: cities[i % 3],
note: i % 2 === 0 ? '' : 'Needs a check',
})),
rowKey: 'id',
};<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Set column defaults once</title>
</head>
<body>
<div id="grid" style="height: 260px"></div>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script>
const names = ['Liam Carter', 'Emma Stone', 'Noah Hayes', 'Olivia Reed', 'Ethan Cole', 'Ava Lane'];
const teams = ['Dev', 'Design', 'Sales'];
const cities = ['Seattle', 'Boston', 'Denver'];
// columnDefaults is the default definition laid under every column. A value a column states itself always wins (here only 'Note' sets its own width).
// defaultColumnWidth is the width of columns that do not set one.
const options = {
columnDefaults: {
align: 'center',
editable: true,
headerTooltip: 'Centered and editable by the default definition',
},
defaultColumnWidth: 110,
columns: [
{ id: 'name', title: 'Name' },
{ id: 'team', title: 'Team' },
{ id: 'city', title: 'City' },
{ id: 'note', title: 'Note', width: 220, align: 'start' },
],
rows: names.map((name, i) => ({
id: i + 1,
name,
team: teams[i % 3],
city: cities[i % 3],
note: i % 2 === 0 ? '' : 'Needs a check',
})),
rowKey: 'id',
};
options.ariaLabel = "Set column defaults once";
const api = MaxGrid.createGrid(document.getElementById('grid'), options);
</script>
</body>
</html>When you click, the example code is sent to StackBlitz or CodeSandbox. Nothing is sent before you click.
import { Grid } from '@maxgrid/react';
import { options, type Row } from './example';
export function ExampleGrid() {
return (
<>
<Grid style={{ height: 260 }} options={options} />
</>
);
}import type { GridOptions } from '@maxgrid/react';
export interface Row {
id: number;
name: string;
team: string;
city: string;
note: string;
}
const names = ['Liam Carter', 'Emma Stone', 'Noah Hayes', 'Olivia Reed', 'Ethan Cole', 'Ava Lane'];
const teams = ['Dev', 'Design', 'Sales'];
const cities = ['Seattle', 'Boston', 'Denver'];
// columnDefaults is the default definition laid under every column. A value a column states itself always wins (here only 'Note' sets its own width).
// defaultColumnWidth is the width of columns that do not set one.
export const options: GridOptions<Row> = {
columnDefaults: {
align: 'center',
editable: true,
headerTooltip: 'Centered and editable by the default definition',
},
defaultColumnWidth: 110,
columns: [
{ id: 'name', title: 'Name' },
{ id: 'team', title: 'Team' },
{ id: 'city', title: 'City' },
{ id: 'note', title: 'Note', width: 220, align: 'start' },
],
rows: names.map((name, i) => ({
id: i + 1,
name,
team: teams[i % 3] as string,
city: cities[i % 3] as string,
note: i % 2 === 0 ? '' : 'Needs a check',
})),
rowKey: 'id',
};When you click, the example code is sent to StackBlitz or CodeSandbox. Nothing is sent before you click.
<script setup lang="ts">
import { Grid } from '@maxgrid/vue';
import { options, type Row } from './example';
</script>
<template>
<Grid style="height: 260px" :options="options" />
</template>import type { GridOptions } from '@maxgrid/vue';
export interface Row {
id: number;
name: string;
team: string;
city: string;
note: string;
}
const names = ['Liam Carter', 'Emma Stone', 'Noah Hayes', 'Olivia Reed', 'Ethan Cole', 'Ava Lane'];
const teams = ['Dev', 'Design', 'Sales'];
const cities = ['Seattle', 'Boston', 'Denver'];
// columnDefaults is the default definition laid under every column. A value a column states itself always wins (here only 'Note' sets its own width).
// defaultColumnWidth is the width of columns that do not set one.
export const options: GridOptions<Row> = {
columnDefaults: {
align: 'center',
editable: true,
headerTooltip: 'Centered and editable by the default definition',
},
defaultColumnWidth: 110,
columns: [
{ id: 'name', title: 'Name' },
{ id: 'team', title: 'Team' },
{ id: 'city', title: 'City' },
{ id: 'note', title: 'Note', width: 220, align: 'start' },
],
rows: names.map((name, i) => ({
id: i + 1,
name,
team: teams[i % 3] as string,
city: cities[i % 3] as string,
note: i % 2 === 0 ? '' : 'Needs a check',
})),
rowKey: 'id',
};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 } from '@maxgrid/angular';
import { options, type Row } from './example';
@Component({
selector: 'app-example-grid',
standalone: true,
imports: [GridComponent],
template: `
<mx-grid style="height: 260px" [options]="options" />
`,
})
export class ExampleGridComponent {
readonly options = options;
}import type { GridOptions } from '@maxgrid/angular';
export interface Row {
id: number;
name: string;
team: string;
city: string;
note: string;
}
const names = ['Liam Carter', 'Emma Stone', 'Noah Hayes', 'Olivia Reed', 'Ethan Cole', 'Ava Lane'];
const teams = ['Dev', 'Design', 'Sales'];
const cities = ['Seattle', 'Boston', 'Denver'];
// columnDefaults is the default definition laid under every column. A value a column states itself always wins (here only 'Note' sets its own width).
// defaultColumnWidth is the width of columns that do not set one.
export const options: GridOptions<Row> = {
columnDefaults: {
align: 'center',
editable: true,
headerTooltip: 'Centered and editable by the default definition',
},
defaultColumnWidth: 110,
columns: [
{ id: 'name', title: 'Name' },
{ id: 'team', title: 'Team' },
{ id: 'city', title: 'City' },
{ id: 'note', title: 'Note', width: 220, align: 'start' },
],
rows: names.map((name, i) => ({
id: i + 1,
name,
team: teams[i % 3] as string,
city: cities[i % 3] as string,
note: i % 2 === 0 ? '' : 'Needs a check',
})),
rowKey: 'id',
};