34540-vm/assets/js/main.js
2025-10-01 06:57:10 +00:00

56 lines
2.2 KiB
JavaScript

document.addEventListener('DOMContentLoaded', function () {
// Initialize tooltips
const tooltipTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="tooltip"]'))
const tooltipList = tooltipTriggerList.map(function (tooltipTriggerEl) {
return new bootstrap.Tooltip(tooltipTriggerEl)
});
// Live search functionality
const searchInput = document.getElementById('searchInput');
const tableBody = document.getElementById('contactTableBody');
const tableRows = tableBody.getElementsByTagName('tr');
searchInput.addEventListener('keyup', function() {
const filter = searchInput.value.toLowerCase();
for (let i = 0; i < tableRows.length; i++) {
const row = tableRows[i];
const cells = row.getElementsByTagName('td');
let text = '';
for (let j = 0; j < cells.length; j++) {
const cell = cells[j];
if (cell) {
text += cell.textContent || cell.innerText;
}
}
if (text.toLowerCase().indexOf(filter) > -1) {
row.style.display = "";
} else {
row.style.display = "none";
}
}
});
// Table sorting functionality
const headers = document.querySelectorAll('.sortable-header');
headers.forEach(header => {
header.addEventListener('click', function() {
const table = this.closest('table');
const tbody = table.querySelector('tbody');
const columnIndex = parseInt(this.getAttribute('data-column-index'));
const rows = Array.from(tbody.querySelectorAll('tr'));
// Simple A-Z string sort
const sortedRows = rows.sort((a, b) => {
const aColText = a.querySelector(`td:nth-child(${columnIndex + 1})`).textContent.trim();
const bColText = b.querySelector(`td:nth-child(${columnIndex + 1})`).textContent.trim();
return aColText.localeCompare(bColText);
});
// Re-append sorted rows
while (tbody.firstChild) {
tbody.removeChild(tbody.firstChild);
}
tbody.append(...sortedRows);
});
});
});