React Gantt - Jotai 튜토리얼
이 튜토리얼은 Vite로 React TypeScript 애플리케이션을 만들고, DHTMLX React Gantt 컴포넌트를 통합하며, Jotai로 상태를 관리하는 과정을 안내합니다.
사전 준비
- React, TypeScript, Vite, 그리고 Jotai에 대한 기본 지식
- 권장: 데이터 바인딩 모드와 이 튜토리얼이 기반으로 하는
data.save콜백을 이해하기 위해 Basics 를 읽으세요.
빠른 설정 - 프로젝트 생성
시작하기 전에 Node.js를 설치하세요: https://nodejs.org/en/
Vite React + TypeScript 프로젝트를 생성합니다:
npm create vite@latest react-gantt-jotai-demo -- --template react-ts
cd react-gantt-jotai-demo
이제 필요한 의존 성을 설치합니다.
- For npm:
npm install jotai @mui/material @mui/icons-material @emotion/react @emotion/styled
- For yarn:
yarn add jotai @mui/material @mui/icons-material @emotion/react @emotion/styled
그다음 React Gantt 패키지를 설치합니다.
Installing React Gantt
React Gantt 설치는 React Gantt 설치 가이드에 설명되어 있습니다.
이 튜토리얼에서는 평가 패키지를 사용합니다:
npm install @dhtmlx/trial-react-gantt
또는
yarn add @dhtmlx/trial-react-gantt
Professional 패키지를 이미 사용 중인 경우 명령과 import에서 @dhtmlx/trial-react-gantt를 @dhx/react-gantt로 교체하십시오.
이제 dev 서버를 시작합니다:
npm run dev
이제 (http://localhost:5173) 에서 React 프로젝트가 실행 중일 것입니다.
노트
Gantt가 본문 전체 공간을 차지하도록 하려면 src 폴더에 있는 App.css의 기본 스타일을 제거하고 다음 스타일을 추가해야 합니다:
#root {
margin: 0;
padding: 0;
height: 100%;
width: 100%;
}
샘플 데이터 및 구성 설정
간트 차트용 초기 데이터를 포함하는 샘플 데이터를 src/seed/Seed.ts에 생성합니다:
import type { SerializedTask, Link, GanttConfig } from '@dhtmlx/trial-react-gantt';
export type ZoomLevel = 'day' | 'month' | 'year';
export const defaultZoomLevels: NonNullable<GanttConfig['zoom']> = {
current: 'day',
levels: [
{ name: 'day', scale_height: 27, min_column_width: 80, scales: [{ unit: 'day', step: 1, format: '%d %M' }] },
{ name: 'month', scale_height: 50, min_column_width: 120, scales: [{ unit: 'month', format: '%F, %Y' }, { unit: 'week', format: 'Week #%W' }] },
{ name: 'year', scale_height: 50, min_column_width: 30, scales: [{ unit: 'year', step: 1, format: '%Y' }] },
],
};
export const seedTasks: SerializedTask[] = [
{ id: 1, text: 'Office itinerancy', type: 'project', start_date: new Date(2025, 3, 2).toISOString(), duration: 17, progress: 0.4, parent: 0, open: true },
{ id: 2, text: 'Office facing', type: 'project', start_date: new Date(2025, 3, 2).toISOString(), duration: 8, progress: 0.6, parent: 1, open: true },
{ id: 3, text: 'Furniture installation', type: 'project', start_date: new Date(2025, 3, 11).toISOString(), duration: 8, progress: 0.6, parent: 1, open: true },
{ id: 4, text: 'The employee relocation', type: 'project', start_date: new Date(2025, 3, 13).toISOString(), duration: 5, progress: 0.5, parent: 1, priority: 3, open: true },
{ id: 5, text: 'Interior office', type: 'task', start_date: new Date(2025, 3, 3).toISOString(), duration: 7, progress: 0.6, parent: 2, priority: 1 },
{ id: 6, text: 'Air conditioners check', type: 'task', start_date: new Date(2025, 3, 3).toISOString(), duration: 7, progress: 0.6, parent: 2, priority: 2 },
{ id: 7, text: 'Workplaces preparation', type: 'task', start_date: new Date(2025, 3, 12).toISOString(), duration: 8, progress: 0.6, parent: 3 },
{ id: 8, text: 'Preparing workplaces', type: 'task', start_date: new Date(2025, 3, 14).toISOString(), duration: 5, progress: 0.5, parent: 4, priority: 1 },
{ id: 9, text: 'Workplaces importation', type: 'task', start_date: new Date(2025, 3, 21).toISOString(), duration: 4, progress: 0.5, parent: 4 },
{ id: 10, text: 'Workplaces exportation', type: 'task', start_date: new Date(2025, 3, 27).toISOString(), duration: 3, progress: 0.5, parent: 4, priority: 2 }
];
export const seedLinks: Link[] = [
{ id: 2, source: 2, target: 3, type: '0' },
{ id: 3, source: 3, target: 4, type: '0' },
{ id: 7, source: 8, target: 9, type: '0' }
];