-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcard.js
52 lines (40 loc) · 1.82 KB
/
card.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import salesData from './salesByCategory.json' assert { type: 'json' };
function displaySalesData(categoryFilter, monthFilter) {
const salesContainer = document.getElementById('sales-container');
salesContainer.innerHTML = ''; // Clear any existing content
let filteredData = salesData.total_sales;
if (monthFilter && monthFilter !== 'all') {
filteredData = salesData.monthly_sales.filter(item => item.periode === monthFilter);
}
if (categoryFilter && categoryFilter !== 'all') {
filteredData = filteredData.filter(item => item.Category.toLowerCase() === categoryFilter.toLowerCase());
}
filteredData.forEach((item, index) => {
const listItem = document.createElement('li');
listItem.className = 'box';
const icon = document.createElement('div');
icon.className = 'bx';
// You can customize this part
const textContainer = document.createElement('div');
textContainer.className = 'text';
textContainer.innerHTML = `
<h3>${item.total_sales || item.total_quantity}</h3>
<p>${item.Category}</p>
`;
listItem.appendChild(icon);
listItem.appendChild(textContainer);
salesContainer.appendChild(listItem);
});
}
// Initial call to display all data
displaySalesData('all', 'all');
// Event listener for the filter
const categoryFilter = document.getElementById('category-filter');
const monthFilter = document.getElementById('month-filter');
function updateFilters() {
const selectedCategory = categoryFilter.value;
const selectedMonth = monthFilter.value;
displaySalesData(selectedCategory, selectedMonth);
}
categoryFilter.addEventListener('change', updateFilters);
monthFilter.addEventListener('change', updateFilters);