const { createApp, ref, onMounted } = Vue;
createApp({
setup() {
const gridHost = ref(null);
const selectedRow = ref(null);
const editLog = ref([]);
function generateData() {
const countries = ['대한민국', '미국', '일본', '독일', '프랑스'];
return countries.map((country, i) => ({
id: i + 1,
country,
sales: Math.round(Math.random() * 10000),
expenses: Math.round(Math.random() * 5000)
}));
}
function onSelectionChanged(sender) {
const item = sender.collectionView?.currentItem;
selectedRow.value = item ? { ...item } : null;
}
function onCellEditEnded(sender, e) {
const newValue = sender.getCellData(e.row, e.col, true);
const colHeader = sender.columns[e.col].header;
editLog.value.unshift(`[${colHeader}] 수정 → ${newValue}`);
if (editLog.value.length > 5) editLog.value.pop();
}
onMounted(() => {
const grid = new wijmo.grid.FlexGrid(gridHost.value, {
itemsSource: generateData(),
autoGenerateColumns: false,
columns: [
{ binding: 'id', header: '번호', width: 60, isReadOnly: true },
{ binding: 'country', header: '국가', width: 120 },
{ binding: 'sales', header: '매출', format: 'n0', width: 100 },
{ binding: 'expenses', header: '비용', format: 'n0', width: 100 }
]
});
grid.autoSizeColumns();
grid.selectionChanged.addHandler(onSelectionChanged);
grid.cellEditEnded.addHandler(onCellEditEnded);
});
return { gridHost, selectedRow, editLog };
},
template: `
<div style="padding:16px;font-family:sans-serif;">
<p style="margin:0 0 8px;color:#666;font-size:13px;">
행을 클릭해 선택하거나, 셀을 더블클릭해 값을 편집해 보세요.
</p>
<div ref="gridHost" style="max-height:260px;"></div>
<div style="margin-top:12px;display:flex;gap:16px;">
<div v-if="selectedRow" style="flex:1;background:#f0f4ff;padding:12px;border-radius:6px;font-size:14px;">
<strong>선택된 행</strong><br />
국가: {{ selectedRow.country }}<br />
매출: {{ selectedRow.sales?.toLocaleString() }}원
</div>
<div v-if="editLog.length" style="flex:1;background:#fff8e1;padding:12px;border-radius:6px;font-size:14px;">
<strong>편집 내역</strong>
<ul style="margin:6px 0 0;padding-left:18px;">
<li v-for="(log, i) in editLog" :key="i">{{ log }}</li>
</ul>
</div>
</div>
</div>
`
}).mount('#app');