|
| 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>Orders Table with Filters</title> |
| 7 | + <style> |
| 8 | + /* General styles */ |
| 9 | + content { |
| 10 | + width: 100%; |
| 11 | + } |
| 12 | + |
| 13 | + .header { |
| 14 | + box-sizing: border-box; |
| 15 | + } |
| 16 | + |
| 17 | + #content #section-1 .container-fluid { |
| 18 | + max-width: none; |
| 19 | + } |
| 20 | + |
| 21 | + .main-container { |
| 22 | + background-color: #969696; |
| 23 | + } |
| 24 | + |
| 25 | + .table-container { |
| 26 | + width: 100%; |
| 27 | + overflow-x: auto; |
| 28 | + background: #afafaf; |
| 29 | + border-radius: 8px; |
| 30 | + padding: 20px; |
| 31 | + box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1); |
| 32 | + } |
| 33 | + |
| 34 | + /* Table styles */ |
| 35 | + table { |
| 36 | + width: 100%; |
| 37 | + border-collapse: collapse; |
| 38 | + min-width: 1200px; /* Minimum width to allow horizontal scrolling */ |
| 39 | + } |
| 40 | + |
| 41 | + td { |
| 42 | + padding: 12px 16px; |
| 43 | + text-align: left; |
| 44 | + border-bottom: 1px solid #3a3a50; |
| 45 | + border-left: 1px solid #3a3a50; |
| 46 | + border-right: 1px solid #3a3a50; |
| 47 | + } |
| 48 | + |
| 49 | + .table-container th.custom-header-class { |
| 50 | + padding: 8px 16px; |
| 51 | + text-align: center; |
| 52 | + border-left: 1px solid #2c2c3d; |
| 53 | + border-right: 1px solid #2c2c3d; |
| 54 | + background-color: #0a613b; |
| 55 | + font-weight: 500; |
| 56 | + color: #dcdfe4; |
| 57 | + white-space: nowrap; /* Prevent headers from wrapping */ |
| 58 | + } |
| 59 | + |
| 60 | + td { |
| 61 | + border-top: 1px solid #2c2f3a; |
| 62 | + white-space: nowrap; /* Prevent content from wrapping */ |
| 63 | + color: #222222; |
| 64 | + } |
| 65 | + |
| 66 | + tr:hover { |
| 67 | + } |
| 68 | + |
| 69 | + /* Input styles */ |
| 70 | + .filter-input { |
| 71 | + width: 100%; |
| 72 | + padding: 6px; |
| 73 | + border: 1px solid #2c2f3a; |
| 74 | + border-radius: 4px; |
| 75 | + background-color: #a0a0a0; |
| 76 | + color: #1d1d1d; |
| 77 | + font-size: 12px; |
| 78 | + box-sizing: border-box; |
| 79 | + } |
| 80 | + |
| 81 | + .filter-input::placeholder { |
| 82 | + color: #6b7280; |
| 83 | + } |
| 84 | + |
| 85 | + /* Pagination styles */ |
| 86 | + .pagination { |
| 87 | + display: flex; |
| 88 | + justify-content: center; |
| 89 | + gap: 8px; |
| 90 | + margin-top: 20px; /* Space between table and pagination */ |
| 91 | + } |
| 92 | + |
| 93 | + .pagination button { |
| 94 | + background-color: #0b6a41; |
| 95 | + border: none; |
| 96 | + color: #ffffff; |
| 97 | + padding: 8px 12px; |
| 98 | + border-radius: 6px; |
| 99 | + cursor: pointer; |
| 100 | + } |
| 101 | + |
| 102 | + .pagination button:hover { |
| 103 | + background-color: #0a613b; |
| 104 | + } |
| 105 | + |
| 106 | + .pagination button.active { |
| 107 | + background-color: #095836; |
| 108 | + color: #ffffff; |
| 109 | + } |
| 110 | + |
| 111 | + /* Icon for the right menu dots */ |
| 112 | + .icon-menu { |
| 113 | + cursor: pointer; |
| 114 | + color: #9ca3af; |
| 115 | + font-size: 20px; |
| 116 | + text-align: center; |
| 117 | + } |
| 118 | + </style> |
| 119 | + </head> |
| 120 | + <body> |
| 121 | + <!-- Table container --> |
| 122 | + <div class="main-container"> |
| 123 | + <div class="table-container"> |
| 124 | + <table id="radiationTable"> |
| 125 | + <thead> |
| 126 | + <tr> |
| 127 | + <th class="custom-header-class">Year</th> |
| 128 | + <th class="custom-header-class">Paper Name</th> |
| 129 | + <th class="custom-header-class">Author(s)</th> |
| 130 | + <th class="custom-header-class">Part Number</th> |
| 131 | + <th class="custom-header-class">Type</th> |
| 132 | + <th class="custom-header-class">Manufacturer</th> |
| 133 | + <th class="custom-header-class"> |
| 134 | + Testing Location |
| 135 | + </th> |
| 136 | + <th class="custom-header-class">Testing Type</th> |
| 137 | + <th class="custom-header-class">Data Type</th> |
| 138 | + <th class="custom-header-class">Custom Field 1</th> |
| 139 | + <th class="custom-header-class">Custom Field 2</th> |
| 140 | + <th class="custom-header-class">Custom Field 3</th> |
| 141 | + <th class="custom-header-class">Custom Field 4</th> |
| 142 | + <th class="custom-header-class">Custom Field 5</th> |
| 143 | + <th class="custom-header-class">Custom Field 6</th> |
| 144 | + <th class="custom-header-class">Custom Field 7</th> |
| 145 | + <th class="custom-header-class">Custom Field 8</th> |
| 146 | + <th class="custom-header-class">Custom Field 9</th> |
| 147 | + <th class="custom-header-class">Custom Field 10</th> |
| 148 | + <th class="custom-header-class">Custom Field 11</th> |
| 149 | + <th class="custom-header-class">Custom Field 12</th> |
| 150 | + <th class="custom-header-class">Custom Field 13</th> |
| 151 | + <th class="custom-header-class">Custom Field 14</th> |
| 152 | + <th class="custom-header-class">Custom Field 15</th> |
| 153 | + <th class="custom-header-class">Custom Field 16</th> |
| 154 | + </tr> |
| 155 | + <tr> |
| 156 | + <th class="custom-header-class"> |
| 157 | + <input class="filter-input" type="text" /> |
| 158 | + </th> |
| 159 | + <th class="custom-header-class"> |
| 160 | + <input class="filter-input" type="text" /> |
| 161 | + </th> |
| 162 | + <th class="custom-header-class"> |
| 163 | + <input class="filter-input" type="text" /> |
| 164 | + </th> |
| 165 | + <th class="custom-header-class"> |
| 166 | + <input class="filter-input" type="text" /> |
| 167 | + </th> |
| 168 | + <th class="custom-header-class"> |
| 169 | + <input class="filter-input" type="text" /> |
| 170 | + </th> |
| 171 | + <th class="custom-header-class"> |
| 172 | + <input class="filter-input" type="text" /> |
| 173 | + </th> |
| 174 | + <th class="custom-header-class"> |
| 175 | + <input class="filter-input" type="text" /> |
| 176 | + </th> |
| 177 | + <th class="custom-header-class"> |
| 178 | + <input class="filter-input" type="text" /> |
| 179 | + </th> |
| 180 | + <th class="custom-header-class"> |
| 181 | + <input class="filter-input" type="text" /> |
| 182 | + </th> |
| 183 | + <th class="custom-header-class"> |
| 184 | + <input class="filter-input" type="text" /> |
| 185 | + </th> |
| 186 | + <th class="custom-header-class"> |
| 187 | + <input class="filter-input" type="text" /> |
| 188 | + </th> |
| 189 | + <th class="custom-header-class"> |
| 190 | + <input class="filter-input" type="text" /> |
| 191 | + </th> |
| 192 | + <th class="custom-header-class"> |
| 193 | + <input class="filter-input" type="text" /> |
| 194 | + </th> |
| 195 | + <th class="custom-header-class"> |
| 196 | + <input class="filter-input" type="text" /> |
| 197 | + </th> |
| 198 | + <th class="custom-header-class"> |
| 199 | + <input class="filter-input" type="text" /> |
| 200 | + </th> |
| 201 | + <th class="custom-header-class"> |
| 202 | + <input class="filter-input" type="text" /> |
| 203 | + </th> |
| 204 | + <th class="custom-header-class"> |
| 205 | + <input class="filter-input" type="text" /> |
| 206 | + </th> |
| 207 | + <th class="custom-header-class"> |
| 208 | + <input class="filter-input" type="text" /> |
| 209 | + </th> |
| 210 | + <th class="custom-header-class"> |
| 211 | + <input class="filter-input" type="text" /> |
| 212 | + </th> |
| 213 | + <th class="custom-header-class"> |
| 214 | + <input class="filter-input" type="text" /> |
| 215 | + </th> |
| 216 | + <th class="custom-header-class"> |
| 217 | + <input class="filter-input" type="text" /> |
| 218 | + </th> |
| 219 | + <th class="custom-header-class"> |
| 220 | + <input class="filter-input" type="text" /> |
| 221 | + </th> |
| 222 | + <th class="custom-header-class"> |
| 223 | + <input class="filter-input" type="text" /> |
| 224 | + </th> |
| 225 | + <th class="custom-header-class"> |
| 226 | + <input class="filter-input" type="text" /> |
| 227 | + </th> |
| 228 | + <th class="custom-header-class"> |
| 229 | + <input class="filter-input" type="text" /> |
| 230 | + </th> |
| 231 | + </tr> |
| 232 | + </thead> |
| 233 | + <tbody> |
| 234 | + <!-- Add rows dynamically --> |
| 235 | + </tbody> |
| 236 | + </table> |
| 237 | + </div> |
| 238 | + |
| 239 | + <!-- Pagination outside the table container --> |
| 240 | + <div class="pagination"> |
| 241 | + |
| 242 | + </div> |
| 243 | + </div> |
| 244 | + <script> |
| 245 | + document.addEventListener("DOMContentLoaded", () => { |
| 246 | + const tableBody = document.querySelector( |
| 247 | + "#radiationTable tbody" |
| 248 | + ); |
| 249 | + const paginationContainer = |
| 250 | + document.querySelector(".pagination"); |
| 251 | + const itemsPerPage = 10; |
| 252 | + let currentPage = 1; |
| 253 | + let data = []; |
| 254 | + |
| 255 | + // Example function to populate the table dynamically (optional) |
| 256 | + fetch("http://localhost:3000/api/dataRequest/tableRequest", { |
| 257 | + method: "POST", |
| 258 | + headers: { |
| 259 | + "Content-Type": "application/json", |
| 260 | + }, |
| 261 | + //body: JSON.stringify(data), |
| 262 | + }) |
| 263 | + .then((response) => response.json()) // Parse JSON response |
| 264 | + .then((fetchData) => { |
| 265 | + console.log(fetchData); |
| 266 | + data = fetchData; |
| 267 | + renderTable(currentPage); // Render the table for the first page |
| 268 | + createPaginationButtons(data.length); |
| 269 | + }); |
| 270 | + |
| 271 | + function renderTable(page) { |
| 272 | + tableBody.innerHTML = ""; |
| 273 | + // Calculate the start and end indices for the current page |
| 274 | + const startIndex = (page - 1) * itemsPerPage; |
| 275 | + const endIndex = startIndex + itemsPerPage; |
| 276 | + |
| 277 | + // Slice the data array to get the items for the current page |
| 278 | + const pageData = data.slice(startIndex, endIndex); |
| 279 | + |
| 280 | + pageData.forEach((item, index) => { |
| 281 | + addRow(item, startIndex + index); |
| 282 | + }); |
| 283 | + } |
| 284 | + |
| 285 | + function addRow(data, index) { |
| 286 | + const row = document.createElement("tr"); |
| 287 | + |
| 288 | + // Assuming 'data' is an object with keys like 'name' and 'message' |
| 289 | + for (let key in data) { |
| 290 | + if (data.hasOwnProperty(key)) { |
| 291 | + if (key === "ROWID") { |
| 292 | + continue; |
| 293 | + } else { |
| 294 | + const cell = document.createElement("td"); |
| 295 | + cell.textContent = data[key]; // Add the value to the cell |
| 296 | + |
| 297 | + row.appendChild(cell); |
| 298 | + } |
| 299 | + } |
| 300 | + } |
| 301 | + let backgroundC = index % 2 === 0 ? "#DADADA" : "#EEEEEE"; |
| 302 | + row.style.backgroundColor = backgroundC; |
| 303 | + tableBody.appendChild(row); |
| 304 | + } |
| 305 | + |
| 306 | + function createPaginationButtons(totalItems) { |
| 307 | + const totalPages = Math.ceil(totalItems / itemsPerPage); |
| 308 | + paginationContainer.innerHTML = ""; // Clear existing pagination buttons |
| 309 | + |
| 310 | + for (let i = 1; i <= totalPages; i++) { |
| 311 | + const button = document.createElement("button"); |
| 312 | + button.textContent = i; |
| 313 | + button.classList.add(i === currentPage ? "active" : null); |
| 314 | + button.addEventListener("click", () => { |
| 315 | + currentPage = i; |
| 316 | + renderTable(currentPage); // Render the new page |
| 317 | + updatePaginationButtons(); |
| 318 | + }); |
| 319 | + paginationContainer.appendChild(button); |
| 320 | + } |
| 321 | + } |
| 322 | + |
| 323 | + function updatePaginationButtons() { |
| 324 | + const buttons = |
| 325 | + paginationContainer.querySelectorAll("button"); |
| 326 | + buttons.forEach((button) => { |
| 327 | + button.classList.remove("active"); |
| 328 | + }); |
| 329 | + const activeButton = paginationContainer.querySelector( |
| 330 | + `button:nth-child(${currentPage})` |
| 331 | + ); |
| 332 | + if (activeButton) { |
| 333 | + activeButton.classList.add("active"); |
| 334 | + } |
| 335 | + } |
| 336 | + }); |
| 337 | + </script> |
| 338 | + </body> |
| 339 | +</html> |
0 commit comments