Spaces:
Sleeping

doluong6 commited on
Commit
594480b
·
verified ·
1 Parent(s): 26aaf8a

Update static/script.js

Browse files
Files changed (1) hide show
  1. static/script.js +23 -30
static/script.js CHANGED
@@ -669,51 +669,46 @@ async function hienThiHSKH() {
669
  return;
670
  }
671
 
672
- const fullIndex = data.columns.indexOf("Full");
673
-
674
- // Nếu đã có bảng thì xoá DataTable trước
675
  if ($.fn.DataTable.isDataTable("#bangHSKH")) {
676
- $('#bangHSKH').DataTable().clear().destroy();
677
  }
678
 
679
- // Tạo header
680
- let theadHtml = "<tr>";
681
- data.columns.forEach(col => {
682
- theadHtml += `<th>${col}</th>`;
683
- });
684
- theadHtml += "</tr>";
685
- $("#bangHSKH thead").html(theadHtml);
686
 
687
- // Tạo body
688
- let tbodyHtml = "";
689
  data.rows.forEach(row => {
690
- tbodyHtml += `<tr>`;
691
- for (let j = 0; j < data.columns.length; j++) {
692
- const col = data.columns[j];
693
- const cell = row[j] || "";
694
- if (["Full", "PYC", "BB", "GCN"].includes(col)) {
695
- const checked = cell.toString().toLowerCase() === "x" ? "checked" : "";
696
- tbodyHtml += `<td><input type="checkbox" class="checkbox-cell" data-col="${col}" ${checked}></td>`;
697
  } else {
698
- tbodyHtml += `<td><input class="input-cell" type="text" value="${cell}"/></td>`;
699
  }
700
- }
701
- tbodyHtml += `</tr>`;
702
  });
703
- $("#bangHSKH tbody").html(tbodyHtml);
704
 
705
- // Khởi tạo lại DataTable
706
  const dt = $("#bangHSKH").DataTable({
707
  scrollX: true,
708
  scrollY: "65vh",
709
  paging: false,
710
  ordering: false,
711
  info: true,
712
- searching: true,
713
  autoWidth: false,
 
714
  language: {
715
  search: "🔍 Tìm kiếm:",
716
- info: "Hiển thị _TOTAL_ dòng",
717
  emptyTable: "Không có dữ liệu"
718
  },
719
  drawCallback: function () {
@@ -721,7 +716,7 @@ async function hienThiHSKH() {
721
  }
722
  });
723
 
724
- // ✅ Cập nhật màu dòng theo checkbox "Full"
725
  function capNhatMauDongHSKH() {
726
  $("#bangHSKH tbody tr").each(function () {
727
  const checkbox = $(this).find('input[data-col="Full"]');
@@ -735,12 +730,10 @@ async function hienThiHSKH() {
735
 
736
  capNhatMauDongHSKH();
737
 
738
- // Khi checkbox thay đổi → cập nhật màu dòng
739
  $(document).off("change", ".checkbox-cell").on("change", ".checkbox-cell", function () {
740
  capNhatMauDongHSKH();
741
  });
742
 
743
- // Hiện nút lưu
744
  document.getElementById("nutLuuHSKH").style.display = "inline-block";
745
 
746
  } catch (error) {
 
669
  return;
670
  }
671
 
 
 
 
672
  if ($.fn.DataTable.isDataTable("#bangHSKH")) {
673
+ $("#bangHSKH").DataTable().clear().destroy();
674
  }
675
 
676
+ // Render thead
677
+ let thead = "<tr>";
678
+ data.columns.forEach(col => thead += `<th>${col}</th>`);
679
+ thead += "</tr>";
680
+ $("#bangHSKH thead").html(thead);
 
 
681
 
682
+ // Render tbody
683
+ let tbody = "";
684
  data.rows.forEach(row => {
685
+ tbody += "<tr>";
686
+ row.forEach((cell, i) => {
687
+ const colName = data.columns[i];
688
+ const val = cell || "";
689
+ if (["Full", "PYC", "BB", "GCN"].includes(colName)) {
690
+ const checked = val.toString().toLowerCase() === "x" ? "checked" : "";
691
+ tbody += `<td><input type="checkbox" class="checkbox-full checkbox-cell" data-col="${colName}" ${checked}></td>`;
692
  } else {
693
+ tbody += `<td><input type="text" class="input-cell" value="${val}"></td>`;
694
  }
695
+ });
696
+ tbody += "</tr>";
697
  });
698
+ $("#bangHSKH tbody").html(tbody);
699
 
700
+ // DataTable
701
  const dt = $("#bangHSKH").DataTable({
702
  scrollX: true,
703
  scrollY: "65vh",
704
  paging: false,
705
  ordering: false,
706
  info: true,
 
707
  autoWidth: false,
708
+ searching: true,
709
  language: {
710
  search: "🔍 Tìm kiếm:",
711
+ info: "Tổng cộng _TOTAL_ dòng",
712
  emptyTable: "Không có dữ liệu"
713
  },
714
  drawCallback: function () {
 
716
  }
717
  });
718
 
719
+ // ✅ Tô màu theo Full
720
  function capNhatMauDongHSKH() {
721
  $("#bangHSKH tbody tr").each(function () {
722
  const checkbox = $(this).find('input[data-col="Full"]');
 
730
 
731
  capNhatMauDongHSKH();
732
 
 
733
  $(document).off("change", ".checkbox-cell").on("change", ".checkbox-cell", function () {
734
  capNhatMauDongHSKH();
735
  });
736
 
 
737
  document.getElementById("nutLuuHSKH").style.display = "inline-block";
738
 
739
  } catch (error) {