const productData = [
{ id: 1, product: 'FlexGrid Pro', qty: 12, price: 350000, discount: 5 },
{ id: 2, product: 'FlexChart Std', qty: 7, price: 180000, discount: 0 },
{ id: 3, product: 'OLAP Engine', qty: 3, price: 950000, discount: 10 },
{ id: 4, product: 'InputPanel', qty: 25, price: 95000, discount: 3 },
];
const errorMsg = document.getElementById('errorMsg');
const grid = new wijmo.grid.FlexGrid('#validGrid', {
itemsSource: productData,
columns: [
{ binding: 'id', header: 'ID', isReadOnly: true, width: 55 },
{ binding: 'product', header: '제품명', isReadOnly: true, width: 150 },
{ binding: 'qty', header: '수량', format: 'n0', width: 90 },
{ binding: 'price', header: '단가 (원)', format: 'n0', width: 130 },
{ binding: 'discount', header: '할인율 (%)', format: 'n1', width: 110 },
]
});
grid.cellEditEnding.addHandler(function(sender, args) {
const col = sender.columns[args.col];
const editor = sender.activeEditor;
const rawValue = editor ? editor.value.replace(/,/g, '') : '';
const newVal = parseFloat(rawValue);
let msg = '';
if (col.binding === 'qty') {
if (isNaN(newVal) || newVal < 1 || !Number.isInteger(newVal)) {
msg = '수량은 1 이상의 정수여야 합니다.';
}
} else if (col.binding === 'price') {
if (isNaN(newVal) || newVal <= 0) {
msg = '단가는 0보다 큰 값이어야 합니다.';
}
} else if (col.binding === 'discount') {
if (isNaN(newVal) || newVal < 0 || newVal > 100) {
msg = '할인율은 0~100 사이 값이어야 합니다.';
}
}
if (msg) {
args.cancel = true;
args.stayInEditMode = true;
errorMsg.textContent = '⚠ ' + msg;
if (editor) editor.style.outline = '2px solid #e74c3c';
} else {
errorMsg.textContent = '';
if (editor) editor.style.outline = '';
}
});
grid.cellEditEnded.addHandler(function(sender, args) {
errorMsg.textContent = '';
});