JSX
const { useRef, useEffect } = React;
function App() {
const gridHost = useRef(null);
useEffect(() => {
const data = [
{ product: '스마트폰', category: '전자기기', sales: 1250, revenue: 125000000, growth: 0.23 },
{ product: '노트북', category: '전자기기', sales: 890, revenue: 98000000, growth: 0.15 },
{ product: '무선이어폰', category: '액세서리', sales: 2340, revenue: 46800000, growth: 0.42 },
{ product: '태블릿', category: '전자기기', sales: 670, revenue: 73700000, growth: 0.08 },
{ product: '스마트워치', category: '웨어러블', sales: 1100, revenue: 55000000, growth: 0.31 },
{ product: '키보드', category: '액세서리', sales: 3200, revenue: 32000000, growth: 0.19 },
{ product: '모니터', category: '주변기기', sales: 450, revenue: 67500000, growth: 0.05 },
{ product: '마우스', category: '액세서리', sales: 4100, revenue: 20500000, growth: 0.27 },
];
const grid = new wijmo.grid.FlexGrid(gridHost.current, {
autoGenerateColumns: false,
allowSorting: true,
columns: [
{ binding: 'product', header: '제품명', width: 130 },
{ binding: 'category', header: '카테고리', width: 110 },
{ binding: 'sales', header: '판매량', width: 90, format: 'n0' },
{ binding: 'revenue', header: '매출액(원)', width: 145, format: 'n0' },
{ binding: 'growth', header: '성장률', width: '*', minWidth: 90, format: 'p1' },
],
itemsSource: data,
});
return () => grid.dispose();
}, []);
return (
<div style={{ fontFamily: "-apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Segoe UI', Pretendard, sans-serif" }}>
<p style={{ marginBottom: 8, color: '#555', fontSize: 13 }}>
열 헤더를 클릭하면 오름차순/내림차순 정렬이 적용됩니다.
</p>
<div ref={gridHost} className="ios-grid-card" style={{ height: 300 }} />
</div>
);
}
ReactDOM.createRoot(document.getElementById('root')).render(<App />);