JSX
import React, { useState } from 'react';
import * as wjcCore from '@mescius/wijmo';
import * as wjcGrid from '@mescius/wijmo.react.grid';
import '@mescius/wijmo.styles/wijmo.css';
import '@mescius/wijmo.cultures/wijmo.culture.ko'; // 한국어 문화권 — 날짜·숫자·필터 UI 한글화
wjcCore.setLicenseKey('YOUR_LICENSE_KEY');
function getData() {
const regions = ['서울', '부산', '대구', '인천', '광주'];
const categories = ['전자제품', '의류', '식품', '가구', '스포츠'];
return Array.from({ length: 15 }, (_, i) => ({
id: i + 1,
region: regions[i % regions.length],
category: categories[i % categories.length],
revenue: Math.round(Math.random() * 10000 + 1000),
cost: Math.round(Math.random() * 5000 + 500),
date: new Date(2026, i % 12, (i % 28) + 1),
isApproved: i % 2 === 0,
}));
}
export default function App() {
const [data] = useState(getData());
const [selectedItem, setSelectedItem] = useState(null);
// initialized: 컨트롤 초기화 완료 후 실행 (그리드 인스턴스 접근 가능)
// 시그니처: (sender, args) — Wijmo 이벤트 핸들러 표준 형식
const initGrid = (grid, args) => {
// 초기화 후 첫 번째 행을 선택된 상태로 설정
grid.select(0, 0);
};
// selectionChanged: 행/셀 선택이 바뀔 때마다 실행
// sender는 FlexGrid 인스턴스, args는 CellRangeEventArgs
const onSelectionChanged = (sender, args) => {
// sender.selectedItems[0]으로 현재 선택된 행의 데이터 객체를 가져옴
const item = sender.selectedItems[0];
setSelectedItem(item || null);
};
return (
<div style={{ padding: '16px', fontFamily: 'sans-serif' }}>
<h3>지역별 매출 현황</h3>
<wjcGrid.FlexGrid
autoGenerateColumns={false}
itemsSource={data}
style={{ height: '320px' }}
initialized={initGrid}
selectionChanged={onSelectionChanged}
>
<wjcGrid.FlexGridColumn binding="id" header="번호" width={60} isReadOnly={true} />
<wjcGrid.FlexGridColumn binding="region" header="지역" width={80} />
<wjcGrid.FlexGridColumn binding="category" header="카테고리" width={100} />
<wjcGrid.FlexGridColumn binding="revenue" header="매출액" width={110} format="n0" />
<wjcGrid.FlexGridColumn binding="cost" header="비용" width={100} format="n0" />
<wjcGrid.FlexGridColumn binding="date" header="날짜" width={120} format="yyyy-MM-dd" />
<wjcGrid.FlexGridColumn binding="isApproved" header="승인 여부" width={90} />
</wjcGrid.FlexGrid>
{/* 선택된 행 데이터를 별도 패널에 표시 */}
{selectedItem && (
<div style={{
marginTop: '12px',
padding: '12px',
background: '#f0f7ff',
borderRadius: '6px',
fontSize: '14px'
}}>
<strong>선택된 행:</strong>&nbsp;
{selectedItem.region} / {selectedItem.category} /
매출 {selectedItem.revenue.toLocaleString()}원
</div>
)}
</div>
);
}