JavaScript
// 샘플 데이터
var products = [
{ name: 'FlexGrid Pro', category: '그리드', price: 450000, inStock: true },
{ name: 'FlexChart', category: '차트', price: 380000, inStock: true },
{ name: 'InputNumber', category: '입력', price: 120000, inStock: false },
{ name: 'ComboBox', category: '입력', price: 95000, inStock: true },
{ name: 'FlexPie', category: '차트', price: 210000, inStock: false },
{ name: 'MultiSelect', category: '입력', price: 145000, inStock: true },
{ name: 'TreeView', category: '내비게이션', price: 185000, inStock: true }
];
// CollectionView 생성 — 초기 정렬을 가격 내림차순으로 설정
var cv = new wijmo.collections.CollectionView(products, {
sortDescriptions: [
new wijmo.collections.SortDescription('price', false) // false = 내림차순
]
});
// FlexGrid에 CollectionView 바인딩
var theGrid = new wijmo.grid.FlexGrid('#theGrid', {
autoGenerateColumns: false,
columns: [
{ binding: 'name', header: '제품명', width: '2*' },
{ binding: 'category', header: '카테고리', width: '*' },
{ binding: 'price', header: '가격(원)', width: '*', format: 'n0' },
{ binding: 'inStock', header: '재고', width: 80 }
],
itemsSource: cv
});
// 버튼 클릭으로 필터 적용: 재고 있는 제품만 표시
document.getElementById('btnFilter').addEventListener('click', function() {
cv.filter = function(item) {
return item.inStock === true;
};
});
// 필터 초기화
document.getElementById('btnClearFilter').addEventListener('click', function() {
cv.filter = null;
});