JSX
const { useRef, useEffect } = React;
const employees = [
{ name: '김민준', department: '개발팀', salary: 85000, active: true, hireDate: new Date(2020, 2, 15) },
{ name: '이서연', department: '마케팅', salary: 72000, active: true, hireDate: new Date(2019, 5, 1) },
{ name: '박지호', department: '개발팀', salary: 91000, active: false, hireDate: new Date(2018, 0, 10) },
{ name: '최수아', department: '인사팀', salary: 68000, active: true, hireDate: new Date(2021, 8, 20) },
{ name: '정도윤', department: '영업팀', salary: 78000, active: true, hireDate: new Date(2020, 11, 5) },
];
function App() {
const gridHost = useRef(null);
useEffect(() => {
const grid = new wijmo.grid.FlexGrid(gridHost.current, {
itemsSource: employees,
autoGenerateColumns: false,
selectionMode: wijmo.grid.SelectionMode.Row,
isReadOnly: true,
columns: [
{ binding: 'name', header: '이름', width: 120 },
{ binding: 'department', header: '부서', width: 120 },
{ binding: 'salary', header: '연봉', width: 140 },
{ binding: 'active', header: '재직', width: 100 },
{ binding: 'hireDate', header: '입사일', format: 'yyyy-MM-dd', width: 150 },
],
});
grid.formatItem.addHandler((s, e) => {
// RowHeader: FlexGrid 직속 자식 템플릿과 동등 — 행 번호 표시
if (e.panel === s.rowHeaders) {
e.cell.textContent = (e.row + 1).toString();
return;
}
const col = e.panel.columns[e.col];
// 연봉 컬럼: ColumnHeader 아이콘 + Cell 조건부 강조
if (e.panel === s.columnHeaders && col.binding === 'salary') {
e.cell.innerHTML = '<span style="margin-right:4px;">₩</span>' + col.header;
return;
}
if (e.panel === s.cells) {
const item = s.rows[e.row].dataItem;
if (col.binding === 'salary') {
const highlight = item.salary >= 90000;
e.cell.style.color = highlight ? '#1565c0' : '';
e.cell.style.fontWeight = highlight ? 'bold' : '';
e.cell.textContent = item.salary.toLocaleString();
}
// 재직 컬럼: Cell 타입 상태 배지
if (col.binding === 'active') {
e.cell.innerHTML =
'<span style="padding:2px 10px;border-radius:12px;background-color:' +
(item.active ? '#4caf50' : '#9e9e9e') +
';color:#fff;font-size:12px;">' + (item.active ? '재직' : '퇴직') + '</span>';
}
}
});
return () => { if (grid.dispose) grid.dispose(); };
}, []);
return <div ref={gridHost} style={{ width: '100%', height: '320px' }} />;
}
ReactDOM.createRoot(document.getElementById('root')).render(<App />);