undefined - Initial Deployment
Browse files- README.md +7 -5
- index.html +560 -19
README.md
CHANGED
|
@@ -1,10 +1,12 @@
|
|
| 1 |
---
|
| 2 |
-
title:
|
| 3 |
-
emoji:
|
| 4 |
-
colorFrom:
|
| 5 |
-
colorTo:
|
| 6 |
sdk: static
|
| 7 |
pinned: false
|
|
|
|
|
|
|
| 8 |
---
|
| 9 |
|
| 10 |
-
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
|
| 1 |
---
|
| 2 |
+
title: poc-multiview-data-grid
|
| 3 |
+
emoji: 🐳
|
| 4 |
+
colorFrom: yellow
|
| 5 |
+
colorTo: red
|
| 6 |
sdk: static
|
| 7 |
pinned: false
|
| 8 |
+
tags:
|
| 9 |
+
- deepsite
|
| 10 |
---
|
| 11 |
|
| 12 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
index.html
CHANGED
|
@@ -1,19 +1,560 @@
|
|
| 1 |
-
<!
|
| 2 |
-
<html>
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8">
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<title>MultiView Data Grid</title>
|
| 7 |
+
<script src="https://cdn.tailwindcss.com"></script>
|
| 8 |
+
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
|
| 9 |
+
<style>
|
| 10 |
+
.card-grid {
|
| 11 |
+
display: grid;
|
| 12 |
+
grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
|
| 13 |
+
gap: 1.5rem;
|
| 14 |
+
}
|
| 15 |
+
|
| 16 |
+
.data-table {
|
| 17 |
+
width: 100%;
|
| 18 |
+
border-collapse: collapse;
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
.data-table th, .data-table td {
|
| 22 |
+
padding: 0.75rem 1rem;
|
| 23 |
+
text-align: left;
|
| 24 |
+
border-bottom: 1px solid #e5e7eb;
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
.data-table th {
|
| 28 |
+
background-color: #f3f4f6;
|
| 29 |
+
font-weight: 600;
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
.data-table tr:hover {
|
| 33 |
+
background-color: #f9fafb;
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
.pagination {
|
| 37 |
+
display: flex;
|
| 38 |
+
justify-content: center;
|
| 39 |
+
gap: 0.5rem;
|
| 40 |
+
margin-top: 1.5rem;
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
.pagination button {
|
| 44 |
+
padding: 0.5rem 1rem;
|
| 45 |
+
border: 1px solid #e5e7eb;
|
| 46 |
+
border-radius: 0.375rem;
|
| 47 |
+
background-color: white;
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
.pagination button.active {
|
| 51 |
+
background-color: #3b82f6;
|
| 52 |
+
color: white;
|
| 53 |
+
border-color: #3b82f6;
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
.search-filter {
|
| 57 |
+
transition: all 0.3s ease;
|
| 58 |
+
}
|
| 59 |
+
|
| 60 |
+
.search-filter:focus {
|
| 61 |
+
outline: none;
|
| 62 |
+
box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.3);
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
.toggle-switch {
|
| 66 |
+
position: relative;
|
| 67 |
+
display: inline-block;
|
| 68 |
+
width: 60px;
|
| 69 |
+
height: 30px;
|
| 70 |
+
}
|
| 71 |
+
|
| 72 |
+
.toggle-switch input {
|
| 73 |
+
opacity: 0;
|
| 74 |
+
width: 0;
|
| 75 |
+
height: 0;
|
| 76 |
+
}
|
| 77 |
+
|
| 78 |
+
.slider {
|
| 79 |
+
position: absolute;
|
| 80 |
+
cursor: pointer;
|
| 81 |
+
top: 0;
|
| 82 |
+
left: 0;
|
| 83 |
+
right: 0;
|
| 84 |
+
bottom: 0;
|
| 85 |
+
background-color: #ccc;
|
| 86 |
+
transition: .4s;
|
| 87 |
+
border-radius: 34px;
|
| 88 |
+
}
|
| 89 |
+
|
| 90 |
+
.slider:before {
|
| 91 |
+
position: absolute;
|
| 92 |
+
content: "";
|
| 93 |
+
height: 22px;
|
| 94 |
+
width: 22px;
|
| 95 |
+
left: 4px;
|
| 96 |
+
bottom: 4px;
|
| 97 |
+
background-color: white;
|
| 98 |
+
transition: .4s;
|
| 99 |
+
border-radius: 50%;
|
| 100 |
+
}
|
| 101 |
+
|
| 102 |
+
input:checked + .slider {
|
| 103 |
+
background-color: #3b82f6;
|
| 104 |
+
}
|
| 105 |
+
|
| 106 |
+
input:checked + .slider:before {
|
| 107 |
+
transform: translateX(30px);
|
| 108 |
+
}
|
| 109 |
+
|
| 110 |
+
.toggle-icons {
|
| 111 |
+
position: absolute;
|
| 112 |
+
top: 50%;
|
| 113 |
+
transform: translateY(-50%);
|
| 114 |
+
color: white;
|
| 115 |
+
font-size: 12px;
|
| 116 |
+
}
|
| 117 |
+
|
| 118 |
+
.table-icon {
|
| 119 |
+
left: 8px;
|
| 120 |
+
}
|
| 121 |
+
|
| 122 |
+
.grid-icon {
|
| 123 |
+
right: 8px;
|
| 124 |
+
}
|
| 125 |
+
|
| 126 |
+
input:checked + .slider .table-icon {
|
| 127 |
+
opacity: 0;
|
| 128 |
+
}
|
| 129 |
+
|
| 130 |
+
input:not(:checked) + .slider .grid-icon {
|
| 131 |
+
opacity: 0;
|
| 132 |
+
}
|
| 133 |
+
|
| 134 |
+
@media (max-width: 640px) {
|
| 135 |
+
.card-grid {
|
| 136 |
+
grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
|
| 137 |
+
}
|
| 138 |
+
|
| 139 |
+
.data-table th, .data-table td {
|
| 140 |
+
padding: 0.5rem;
|
| 141 |
+
font-size: 0.875rem;
|
| 142 |
+
}
|
| 143 |
+
|
| 144 |
+
.controls-container {
|
| 145 |
+
flex-direction: column;
|
| 146 |
+
gap: 1rem;
|
| 147 |
+
}
|
| 148 |
+
}
|
| 149 |
+
</style>
|
| 150 |
+
</head>
|
| 151 |
+
<body class="bg-gray-50 min-h-screen">
|
| 152 |
+
<div class="container mx-auto px-4 py-8 max-w-7xl">
|
| 153 |
+
<div class="bg-white rounded-lg shadow-md p-6">
|
| 154 |
+
<h1 class="text-2xl font-bold text-gray-800 mb-6">MultiView Data Grid</h1>
|
| 155 |
+
|
| 156 |
+
<div id="multiViewGrid" class="space-y-6">
|
| 157 |
+
<!-- Controls will be inserted here by JavaScript -->
|
| 158 |
+
</div>
|
| 159 |
+
</div>
|
| 160 |
+
</div>
|
| 161 |
+
|
| 162 |
+
<script>
|
| 163 |
+
document.addEventListener('DOMContentLoaded', function() {
|
| 164 |
+
// Sample data
|
| 165 |
+
const sampleData = [
|
| 166 |
+
{ id: 1, name: 'John Doe', email: 'john@example.com', age: 28, status: 'Active', department: 'Engineering' },
|
| 167 |
+
{ id: 2, name: 'Jane Smith', email: 'jane@example.com', age: 32, status: 'Active', department: 'Marketing' },
|
| 168 |
+
{ id: 3, name: 'Robert Johnson', email: 'robert@example.com', age: 45, status: 'Inactive', department: 'Sales' },
|
| 169 |
+
{ id: 4, name: 'Emily Davis', email: 'emily@example.com', age: 24, status: 'Active', department: 'Engineering' },
|
| 170 |
+
{ id: 5, name: 'Michael Brown', email: 'michael@example.com', age: 38, status: 'Active', department: 'HR' },
|
| 171 |
+
{ id: 6, name: 'Sarah Wilson', email: 'sarah@example.com', age: 29, status: 'Inactive', department: 'Marketing' },
|
| 172 |
+
{ id: 7, name: 'David Taylor', email: 'david@example.com', age: 41, status: 'Active', department: 'Engineering' },
|
| 173 |
+
{ id: 8, name: 'Lisa Anderson', email: 'lisa@example.com', age: 35, status: 'Active', department: 'Finance' },
|
| 174 |
+
{ id: 9, name: 'James Martinez', email: 'james@example.com', age: 27, status: 'Inactive', department: 'Sales' },
|
| 175 |
+
{ id: 10, name: 'Jennifer Thomas', email: 'jennifer@example.com', age: 31, status: 'Active', department: 'Marketing' },
|
| 176 |
+
{ id: 11, name: 'Christopher Lee', email: 'chris@example.com', age: 40, status: 'Active', department: 'Engineering' },
|
| 177 |
+
{ id: 12, name: 'Amanda White', email: 'amanda@example.com', age: 26, status: 'Inactive', department: 'HR' }
|
| 178 |
+
];
|
| 179 |
+
|
| 180 |
+
// Columns configuration
|
| 181 |
+
const columns = [
|
| 182 |
+
{ field: 'id', headerName: 'ID', width: 70 },
|
| 183 |
+
{ field: 'name', headerName: 'Name', width: 150 },
|
| 184 |
+
{ field: 'email', headerName: 'Email', width: 200 },
|
| 185 |
+
{ field: 'age', headerName: 'Age', width: 90 },
|
| 186 |
+
{ field: 'department', headerName: 'Department', width: 150 },
|
| 187 |
+
{ field: 'status', headerName: 'Status', width: 120 }
|
| 188 |
+
];
|
| 189 |
+
|
| 190 |
+
// Card renderer function
|
| 191 |
+
function cardRenderer(item) {
|
| 192 |
+
return `
|
| 193 |
+
<div class="bg-white rounded-lg shadow-md overflow-hidden border border-gray-200 hover:shadow-lg transition-shadow duration-300">
|
| 194 |
+
<div class="p-4">
|
| 195 |
+
<div class="flex items-center justify-between mb-3">
|
| 196 |
+
<h3 class="text-lg font-semibold text-gray-800">${item.name}</h3>
|
| 197 |
+
<span class="px-2 py-1 text-xs rounded-full ${item.status === 'Active' ? 'bg-green-100 text-green-800' : 'bg-red-100 text-red-800'}">
|
| 198 |
+
${item.status}
|
| 199 |
+
</span>
|
| 200 |
+
</div>
|
| 201 |
+
<div class="space-y-2 text-sm text-gray-600">
|
| 202 |
+
<p><i class="fas fa-envelope mr-2"></i> ${item.email}</p>
|
| 203 |
+
<p><i class="fas fa-id-card mr-2"></i> ID: ${item.id}</p>
|
| 204 |
+
<p><i class="fas fa-birthday-cake mr-2"></i> Age: ${item.age}</p>
|
| 205 |
+
<p><i class="fas fa-building mr-2"></i> ${item.department}</p>
|
| 206 |
+
</div>
|
| 207 |
+
</div>
|
| 208 |
+
<div class="bg-gray-50 px-4 py-3 flex justify-end">
|
| 209 |
+
<button class="text-blue-600 hover:text-blue-800 text-sm font-medium">
|
| 210 |
+
View Details
|
| 211 |
+
</button>
|
| 212 |
+
</div>
|
| 213 |
+
</div>
|
| 214 |
+
`;
|
| 215 |
+
}
|
| 216 |
+
|
| 217 |
+
// Initialize the MultiViewDataGrid
|
| 218 |
+
const multiViewGrid = new MultiViewDataGrid({
|
| 219 |
+
container: document.getElementById('multiViewGrid'),
|
| 220 |
+
data: sampleData,
|
| 221 |
+
columns: columns,
|
| 222 |
+
cardRenderer: cardRenderer,
|
| 223 |
+
defaultView: 'table',
|
| 224 |
+
itemsPerPage: 6
|
| 225 |
+
});
|
| 226 |
+
|
| 227 |
+
multiViewGrid.render();
|
| 228 |
+
});
|
| 229 |
+
|
| 230 |
+
class MultiViewDataGrid {
|
| 231 |
+
constructor(options) {
|
| 232 |
+
this.container = options.container;
|
| 233 |
+
this.data = options.data || [];
|
| 234 |
+
this.columns = options.columns || [];
|
| 235 |
+
this.cardRenderer = options.cardRenderer || ((item) => `<div>${JSON.stringify(item)}</div>`);
|
| 236 |
+
this.currentView = options.defaultView || 'table';
|
| 237 |
+
this.itemsPerPage = options.itemsPerPage || 10;
|
| 238 |
+
this.currentPage = 1;
|
| 239 |
+
this.searchTerm = '';
|
| 240 |
+
this.sortConfig = { field: null, direction: 'asc' };
|
| 241 |
+
this.filteredData = [...this.data];
|
| 242 |
+
}
|
| 243 |
+
|
| 244 |
+
render() {
|
| 245 |
+
// Clear the container
|
| 246 |
+
this.container.innerHTML = '';
|
| 247 |
+
|
| 248 |
+
// Render controls
|
| 249 |
+
this.renderControls();
|
| 250 |
+
|
| 251 |
+
// Render the current view
|
| 252 |
+
if (this.currentView === 'table') {
|
| 253 |
+
this.renderTableView();
|
| 254 |
+
} else {
|
| 255 |
+
this.renderGridView();
|
| 256 |
+
}
|
| 257 |
+
|
| 258 |
+
// Render pagination
|
| 259 |
+
this.renderPagination();
|
| 260 |
+
}
|
| 261 |
+
|
| 262 |
+
renderControls() {
|
| 263 |
+
const controlsContainer = document.createElement('div');
|
| 264 |
+
controlsContainer.className = 'controls-container flex flex-wrap items-center justify-between gap-4 mb-6';
|
| 265 |
+
|
| 266 |
+
// Search input
|
| 267 |
+
const searchContainer = document.createElement('div');
|
| 268 |
+
searchContainer.className = 'relative flex-1 min-w-[200px]';
|
| 269 |
+
|
| 270 |
+
const searchInput = document.createElement('input');
|
| 271 |
+
searchInput.type = 'text';
|
| 272 |
+
searchInput.placeholder = 'Search...';
|
| 273 |
+
searchInput.className = 'search-filter w-full pl-10 pr-4 py-2 border border-gray-300 rounded-lg focus:border-blue-500';
|
| 274 |
+
searchInput.value = this.searchTerm;
|
| 275 |
+
searchInput.addEventListener('input', (e) => {
|
| 276 |
+
this.searchTerm = e.target.value.toLowerCase();
|
| 277 |
+
this.currentPage = 1;
|
| 278 |
+
this.filterData();
|
| 279 |
+
this.render();
|
| 280 |
+
});
|
| 281 |
+
|
| 282 |
+
const searchIcon = document.createElement('i');
|
| 283 |
+
searchIcon.className = 'fas fa-search absolute left-3 top-1/2 transform -translate-y-1/2 text-gray-400';
|
| 284 |
+
|
| 285 |
+
searchContainer.appendChild(searchIcon);
|
| 286 |
+
searchContainer.appendChild(searchInput);
|
| 287 |
+
|
| 288 |
+
// View toggle
|
| 289 |
+
const toggleContainer = document.createElement('div');
|
| 290 |
+
toggleContainer.className = 'flex items-center gap-3';
|
| 291 |
+
|
| 292 |
+
const toggleLabel = document.createElement('span');
|
| 293 |
+
toggleLabel.className = 'text-sm font-medium text-gray-700';
|
| 294 |
+
toggleLabel.textContent = 'Toggle View:';
|
| 295 |
+
|
| 296 |
+
const toggleWrapper = document.createElement('label');
|
| 297 |
+
toggleWrapper.className = 'toggle-switch';
|
| 298 |
+
|
| 299 |
+
const toggleInput = document.createElement('input');
|
| 300 |
+
toggleInput.type = 'checkbox';
|
| 301 |
+
toggleInput.checked = this.currentView === 'grid';
|
| 302 |
+
toggleInput.addEventListener('change', () => {
|
| 303 |
+
this.currentView = toggleInput.checked ? 'grid' : 'table';
|
| 304 |
+
this.render();
|
| 305 |
+
});
|
| 306 |
+
|
| 307 |
+
const toggleSlider = document.createElement('span');
|
| 308 |
+
toggleSlider.className = 'slider';
|
| 309 |
+
|
| 310 |
+
const tableIcon = document.createElement('i');
|
| 311 |
+
tableIcon.className = 'toggle-icons table-icon fas fa-table';
|
| 312 |
+
|
| 313 |
+
const gridIcon = document.createElement('i');
|
| 314 |
+
gridIcon.className = 'toggle-icons grid-icon fas fa-th';
|
| 315 |
+
|
| 316 |
+
toggleSlider.appendChild(tableIcon);
|
| 317 |
+
toggleSlider.appendChild(gridIcon);
|
| 318 |
+
toggleWrapper.appendChild(toggleInput);
|
| 319 |
+
toggleWrapper.appendChild(toggleSlider);
|
| 320 |
+
|
| 321 |
+
toggleContainer.appendChild(toggleLabel);
|
| 322 |
+
toggleContainer.appendChild(toggleWrapper);
|
| 323 |
+
|
| 324 |
+
// Column selector (for table view)
|
| 325 |
+
if (this.currentView === 'table') {
|
| 326 |
+
const columnSelectContainer = document.createElement('div');
|
| 327 |
+
columnSelectContainer.className = 'w-full md:w-auto';
|
| 328 |
+
|
| 329 |
+
const columnSelectLabel = document.createElement('label');
|
| 330 |
+
columnSelectLabel.className = 'block text-sm font-medium text-gray-700 mb-1';
|
| 331 |
+
columnSelectLabel.textContent = 'Columns:';
|
| 332 |
+
|
| 333 |
+
const columnSelect = document.createElement('select');
|
| 334 |
+
columnSelect.className = 'block w-full pl-3 pr-10 py-2 text-base border border-gray-300 focus:outline-none focus:ring-blue-500 focus:border-blue-500 sm:text-sm rounded-md';
|
| 335 |
+
columnSelect.multiple = true;
|
| 336 |
+
|
| 337 |
+
// Add all columns as options
|
| 338 |
+
this.columns.forEach(col => {
|
| 339 |
+
const option = document.createElement('option');
|
| 340 |
+
option.value = col.field;
|
| 341 |
+
option.textContent = col.headerName;
|
| 342 |
+
option.selected = true;
|
| 343 |
+
columnSelect.appendChild(option);
|
| 344 |
+
});
|
| 345 |
+
|
| 346 |
+
columnSelectContainer.appendChild(columnSelectLabel);
|
| 347 |
+
columnSelectContainer.appendChild(columnSelect);
|
| 348 |
+
controlsContainer.appendChild(columnSelectContainer);
|
| 349 |
+
}
|
| 350 |
+
|
| 351 |
+
controlsContainer.appendChild(searchContainer);
|
| 352 |
+
controlsContainer.appendChild(toggleContainer);
|
| 353 |
+
|
| 354 |
+
this.container.appendChild(controlsContainer);
|
| 355 |
+
}
|
| 356 |
+
|
| 357 |
+
renderTableView() {
|
| 358 |
+
const tableContainer = document.createElement('div');
|
| 359 |
+
tableContainer.className = 'overflow-x-auto';
|
| 360 |
+
|
| 361 |
+
const table = document.createElement('table');
|
| 362 |
+
table.className = 'data-table w-full';
|
| 363 |
+
|
| 364 |
+
// Create table header
|
| 365 |
+
const thead = document.createElement('thead');
|
| 366 |
+
const headerRow = document.createElement('tr');
|
| 367 |
+
|
| 368 |
+
this.columns.forEach(col => {
|
| 369 |
+
const th = document.createElement('th');
|
| 370 |
+
th.textContent = col.headerName;
|
| 371 |
+
th.className = 'cursor-pointer hover:bg-gray-100';
|
| 372 |
+
th.addEventListener('click', () => {
|
| 373 |
+
if (this.sortConfig.field === col.field) {
|
| 374 |
+
this.sortConfig.direction = this.sortConfig.direction === 'asc' ? 'desc' : 'asc';
|
| 375 |
+
} else {
|
| 376 |
+
this.sortConfig.field = col.field;
|
| 377 |
+
this.sortConfig.direction = 'asc';
|
| 378 |
+
}
|
| 379 |
+
this.filterData();
|
| 380 |
+
this.render();
|
| 381 |
+
});
|
| 382 |
+
|
| 383 |
+
// Add sort indicator
|
| 384 |
+
if (this.sortConfig.field === col.field) {
|
| 385 |
+
const sortIcon = document.createElement('i');
|
| 386 |
+
sortIcon.className = `fas fa-sort-${this.sortConfig.direction === 'asc' ? 'up' : 'down'} ml-1`;
|
| 387 |
+
th.appendChild(sortIcon);
|
| 388 |
+
}
|
| 389 |
+
|
| 390 |
+
headerRow.appendChild(th);
|
| 391 |
+
});
|
| 392 |
+
|
| 393 |
+
thead.appendChild(headerRow);
|
| 394 |
+
table.appendChild(thead);
|
| 395 |
+
|
| 396 |
+
// Create table body
|
| 397 |
+
const tbody = document.createElement('tbody');
|
| 398 |
+
|
| 399 |
+
const paginatedData = this.getPaginatedData();
|
| 400 |
+
paginatedData.forEach(item => {
|
| 401 |
+
const row = document.createElement('tr');
|
| 402 |
+
row.className = 'hover:bg-gray-50';
|
| 403 |
+
|
| 404 |
+
this.columns.forEach(col => {
|
| 405 |
+
const td = document.createElement('td');
|
| 406 |
+
td.textContent = item[col.field];
|
| 407 |
+
row.appendChild(td);
|
| 408 |
+
});
|
| 409 |
+
|
| 410 |
+
tbody.appendChild(row);
|
| 411 |
+
});
|
| 412 |
+
|
| 413 |
+
table.appendChild(tbody);
|
| 414 |
+
tableContainer.appendChild(table);
|
| 415 |
+
this.container.appendChild(tableContainer);
|
| 416 |
+
}
|
| 417 |
+
|
| 418 |
+
renderGridView() {
|
| 419 |
+
const gridContainer = document.createElement('div');
|
| 420 |
+
gridContainer.className = 'card-grid';
|
| 421 |
+
|
| 422 |
+
const paginatedData = this.getPaginatedData();
|
| 423 |
+
paginatedData.forEach(item => {
|
| 424 |
+
const card = document.createElement('div');
|
| 425 |
+
card.innerHTML = this.cardRenderer(item);
|
| 426 |
+
gridContainer.appendChild(card);
|
| 427 |
+
});
|
| 428 |
+
|
| 429 |
+
this.container.appendChild(gridContainer);
|
| 430 |
+
}
|
| 431 |
+
|
| 432 |
+
renderPagination() {
|
| 433 |
+
const totalPages = Math.ceil(this.filteredData.length / this.itemsPerPage);
|
| 434 |
+
if (totalPages <= 1) return;
|
| 435 |
+
|
| 436 |
+
const paginationContainer = document.createElement('div');
|
| 437 |
+
paginationContainer.className = 'pagination';
|
| 438 |
+
|
| 439 |
+
// Previous button
|
| 440 |
+
const prevButton = document.createElement('button');
|
| 441 |
+
prevButton.innerHTML = '<i class="fas fa-chevron-left"></i>';
|
| 442 |
+
prevButton.disabled = this.currentPage === 1;
|
| 443 |
+
prevButton.addEventListener('click', () => {
|
| 444 |
+
if (this.currentPage > 1) {
|
| 445 |
+
this.currentPage--;
|
| 446 |
+
this.render();
|
| 447 |
+
}
|
| 448 |
+
});
|
| 449 |
+
paginationContainer.appendChild(prevButton);
|
| 450 |
+
|
| 451 |
+
// Page buttons
|
| 452 |
+
const maxVisiblePages = 5;
|
| 453 |
+
let startPage = Math.max(1, this.currentPage - Math.floor(maxVisiblePages / 2));
|
| 454 |
+
let endPage = Math.min(totalPages, startPage + maxVisiblePages - 1);
|
| 455 |
+
|
| 456 |
+
if (endPage - startPage + 1 < maxVisiblePages) {
|
| 457 |
+
startPage = Math.max(1, endPage - maxVisiblePages + 1);
|
| 458 |
+
}
|
| 459 |
+
|
| 460 |
+
if (startPage > 1) {
|
| 461 |
+
const firstPageButton = document.createElement('button');
|
| 462 |
+
firstPageButton.textContent = '1';
|
| 463 |
+
firstPageButton.addEventListener('click', () => {
|
| 464 |
+
this.currentPage = 1;
|
| 465 |
+
this.render();
|
| 466 |
+
});
|
| 467 |
+
paginationContainer.appendChild(firstPageButton);
|
| 468 |
+
|
| 469 |
+
if (startPage > 2) {
|
| 470 |
+
const ellipsis = document.createElement('span');
|
| 471 |
+
ellipsis.textContent = '...';
|
| 472 |
+
ellipsis.className = 'flex items-center';
|
| 473 |
+
paginationContainer.appendChild(ellipsis);
|
| 474 |
+
}
|
| 475 |
+
}
|
| 476 |
+
|
| 477 |
+
for (let i = startPage; i <= endPage; i++) {
|
| 478 |
+
const pageButton = document.createElement('button');
|
| 479 |
+
pageButton.textContent = i;
|
| 480 |
+
if (i === this.currentPage) {
|
| 481 |
+
pageButton.className = 'active';
|
| 482 |
+
}
|
| 483 |
+
pageButton.addEventListener('click', () => {
|
| 484 |
+
this.currentPage = i;
|
| 485 |
+
this.render();
|
| 486 |
+
});
|
| 487 |
+
paginationContainer.appendChild(pageButton);
|
| 488 |
+
}
|
| 489 |
+
|
| 490 |
+
if (endPage < totalPages) {
|
| 491 |
+
if (endPage < totalPages - 1) {
|
| 492 |
+
const ellipsis = document.createElement('span');
|
| 493 |
+
ellipsis.textContent = '...';
|
| 494 |
+
ellipsis.className = 'flex items-center';
|
| 495 |
+
paginationContainer.appendChild(ellipsis);
|
| 496 |
+
}
|
| 497 |
+
|
| 498 |
+
const lastPageButton = document.createElement('button');
|
| 499 |
+
lastPageButton.textContent = totalPages;
|
| 500 |
+
lastPageButton.addEventListener('click', () => {
|
| 501 |
+
this.currentPage = totalPages;
|
| 502 |
+
this.render();
|
| 503 |
+
});
|
| 504 |
+
paginationContainer.appendChild(lastPageButton);
|
| 505 |
+
}
|
| 506 |
+
|
| 507 |
+
// Next button
|
| 508 |
+
const nextButton = document.createElement('button');
|
| 509 |
+
nextButton.innerHTML = '<i class="fas fa-chevron-right"></i>';
|
| 510 |
+
nextButton.disabled = this.currentPage === totalPages;
|
| 511 |
+
nextButton.addEventListener('click', () => {
|
| 512 |
+
if (this.currentPage < totalPages) {
|
| 513 |
+
this.currentPage++;
|
| 514 |
+
this.render();
|
| 515 |
+
}
|
| 516 |
+
});
|
| 517 |
+
paginationContainer.appendChild(nextButton);
|
| 518 |
+
|
| 519 |
+
this.container.appendChild(paginationContainer);
|
| 520 |
+
}
|
| 521 |
+
|
| 522 |
+
filterData() {
|
| 523 |
+
// Apply search filter
|
| 524 |
+
let filtered = this.data;
|
| 525 |
+
if (this.searchTerm) {
|
| 526 |
+
filtered = this.data.filter(item => {
|
| 527 |
+
return Object.values(item).some(
|
| 528 |
+
val => val.toString().toLowerCase().includes(this.searchTerm)
|
| 529 |
+
);
|
| 530 |
+
});
|
| 531 |
+
}
|
| 532 |
+
|
| 533 |
+
// Apply sorting
|
| 534 |
+
if (this.sortConfig.field) {
|
| 535 |
+
filtered.sort((a, b) => {
|
| 536 |
+
const aValue = a[this.sortConfig.field];
|
| 537 |
+
const bValue = b[this.sortConfig.field];
|
| 538 |
+
|
| 539 |
+
if (aValue < bValue) {
|
| 540 |
+
return this.sortConfig.direction === 'asc' ? -1 : 1;
|
| 541 |
+
}
|
| 542 |
+
if (aValue > bValue) {
|
| 543 |
+
return this.sortConfig.direction === 'asc' ? 1 : -1;
|
| 544 |
+
}
|
| 545 |
+
return 0;
|
| 546 |
+
});
|
| 547 |
+
}
|
| 548 |
+
|
| 549 |
+
this.filteredData = filtered;
|
| 550 |
+
}
|
| 551 |
+
|
| 552 |
+
getPaginatedData() {
|
| 553 |
+
const startIndex = (this.currentPage - 1) * this.itemsPerPage;
|
| 554 |
+
const endIndex = startIndex + this.itemsPerPage;
|
| 555 |
+
return this.filteredData.slice(startIndex, endIndex);
|
| 556 |
+
}
|
| 557 |
+
}
|
| 558 |
+
</script>
|
| 559 |
+
<p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - 🧬 <a href="https://enzostvs-deepsite.hf.space?remix=MVCavalheiroJr/poc-multiview-data-grid" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
|
| 560 |
+
</html>
|