Spaces:
Sleeping

doluong6 commited on
Commit
25b308b
·
verified ·
1 Parent(s): 9f6d495

Update static/script.js

Browse files
Files changed (1) hide show
  1. static/script.js +23 -23
static/script.js CHANGED
@@ -1362,41 +1362,40 @@ async function hienThiBangGia5() {
1362
  const response = await fetch(`${BACKEND_URL}/bang_gia_dungtich_luuluong`);
1363
  const data = await response.json();
1364
 
1365
- if (!data || !data.rows || data.rows.length === 0) {
1366
- document.getElementById("banggia5").innerHTML = "<p>Không có dữ liệu.</p>";
1367
  return;
1368
  }
1369
 
1370
- const table = document.createElement("table");
1371
- table.id = "bangBangGia5";
1372
- table.className = "display styled-table";
1373
 
1374
- const thead = table.createTHead();
1375
- const headerRow = thead.insertRow();
 
 
 
 
 
 
 
 
 
1376
  data.columns.forEach(col => {
1377
- const th = document.createElement("th");
1378
- th.textContent = col;
1379
- headerRow.appendChild(th);
1380
  });
 
1381
 
1382
- const tbody = table.createTBody();
1383
  data.rows.forEach(row => {
1384
- const tr = tbody.insertRow();
1385
  row.forEach(cell => {
1386
- const td = tr.insertCell();
1387
- td.textContent = cell;
1388
  });
 
1389
  });
1390
 
1391
- const container = document.getElementById("banggia5");
1392
- container.innerHTML = "";
1393
- container.appendChild(table);
1394
-
1395
- // Khởi tạo DataTable nếu có jQuery
1396
- if ($.fn.DataTable.isDataTable("#bangBangGia5")) {
1397
- $('#bangBangGia5').DataTable().destroy();
1398
- }
1399
- $('#bangBangGia5').DataTable({
1400
  scrollX: true,
1401
  pageLength: 25
1402
  });
@@ -1405,3 +1404,4 @@ async function hienThiBangGia5() {
1405
  console.error("Lỗi khi tải bảng giá 5:", error);
1406
  }
1407
  }
 
 
1362
  const response = await fetch(`${BACKEND_URL}/bang_gia_dungtich_luuluong`);
1363
  const data = await response.json();
1364
 
1365
+ if (!data || !data.columns || !data.rows) {
1366
+ console.warn("Không có dữ liệu bảng giá 5.");
1367
  return;
1368
  }
1369
 
1370
+ const tableId = "#tableBangGia5";
 
 
1371
 
1372
+ // Clear DataTable nếu đã khởi tạo
1373
+ if ($.fn.DataTable.isDataTable(tableId)) {
1374
+ $(tableId).DataTable().clear().destroy();
1375
+ }
1376
+
1377
+ // Xóa nội dung cũ
1378
+ $(`${tableId} thead`).empty();
1379
+ $(`${tableId} tbody`).empty();
1380
+
1381
+ // Tạo header
1382
+ const headerRow = $("<tr></tr>");
1383
  data.columns.forEach(col => {
1384
+ headerRow.append(`<th>${col}</th>`);
 
 
1385
  });
1386
+ $(`${tableId} thead`).append(headerRow);
1387
 
1388
+ // Tạo body
1389
  data.rows.forEach(row => {
1390
+ const rowHtml = $("<tr></tr>");
1391
  row.forEach(cell => {
1392
+ rowHtml.append(`<td>${cell}</td>`);
 
1393
  });
1394
+ $(`${tableId} tbody`).append(rowHtml);
1395
  });
1396
 
1397
+ // Khởi tạo lại DataTable
1398
+ $(tableId).DataTable({
 
 
 
 
 
 
 
1399
  scrollX: true,
1400
  pageLength: 25
1401
  });
 
1404
  console.error("Lỗi khi tải bảng giá 5:", error);
1405
  }
1406
  }
1407
+