JavaScript
// 주문 데이터 생성 (60건)
var customers = ['한빛전자', '대한물산', '새론테크', '미래상사', '푸른유통'];
var products = ['노트북', '모니터', '키보드', '마우스', '도킹스테이션'];
var data = [];
for (var i = 1; i <= 60; i++) {
var qty = (i % 7) + 1;
var price = 10000 * ((i % 9) + 1);
data.push({
id: i,
customer: customers[i % customers.length],
product: products[i % products.length],
qty: qty,
price: price,
amount: qty * price,
discount: (i % 4) * 5,
tax: Math.round(qty * price * 0.1),
shipping: 3000 * ((i % 3) + 1),
region: ['서울', '경기', '부산', '대구'][i % 4],
manager: ['김민수', '이서연', '박지훈'][i % 3],
memo: '납품 일정 협의 필요'
});
}
// 맨 위에 합계 행 삽입
var totalQty = 0, totalAmount = 0, totalTax = 0;
data.forEach(function (d) {
totalQty += d.qty;
totalAmount += d.amount;
totalTax += d.tax;
});
data.unshift({
id: '',
customer: '합계',
product: '',
qty: totalQty,
price: null,
amount: totalAmount,
discount: null,
tax: totalTax,
shipping: null,
region: '',
manager: '',
memo: ''
});
var grid = new wijmo.grid.FlexGrid('#frozenGrid', {
itemsSource: data,
autoGenerateColumns: false,
allowSorting: wijmo.grid.AllowSorting.None, // 합계 행이 정렬로 이동하지 않도록
frozenColumns: 2, // 왼쪽 2개 열 고정
frozenRows: 1, // 데이터 첫 행(합계) 고정
columns: [
{ binding: 'id', header: '번호', width: 70 },
{ binding: 'customer', header: '고객사', width: 120 },
{ binding: 'product', header: '상품', width: 130 },
{ binding: 'qty', header: '수량', width: 80 },
{ binding: 'price', header: '단가', width: 110, format: 'n0' },
{ binding: 'amount', header: '금액', width: 120, format: 'n0' },
{ binding: 'discount', header: '할인율(%)', width: 100 },
{ binding: 'tax', header: '세액', width: 110, format: 'n0' },
{ binding: 'shipping', header: '배송비', width: 110, format: 'n0' },
{ binding: 'region', header: '지역', width: 100 },
{ binding: 'manager', header: '담당자', width: 110 },
{ binding: 'memo', header: '비고', width: 200 }
],
itemFormatter: function (panel, r, c, cell) {
// 셀 영역의 첫 행(합계)을 강조
if (panel.cellType === wijmo.grid.CellType.Cell && r === 0) {
cell.style.fontWeight = 'bold';
cell.style.backgroundColor = '#fff3cd';
}
}
});
// 버튼에서 고정 열 개수 변경
function setFrozenColumns(count) {
grid.frozenColumns = count;
}
window.setFrozenColumns = setFrozenColumns; // onclick 핸들러용 전역 노출