document.addEventListener('DOMContentLoaded', function () {
document.querySelectorAll('table.tablepress').forEach(table => {
// Wrap table in responsive div if not already
if (!table.parentElement.classList.contains('tablepress-responsive')) {
const wrapper = document.createElement('div');
wrapper.classList.add('tablepress-responsive');
table.parentNode.insertBefore(wrapper, table);
wrapper.appendChild(table);
}
// Generate data-th attributes for stacked view
const headers = Array.from(table.querySelectorAll('thead th')).map(th => th.textContent.trim());
table.querySelectorAll('tbody tr').forEach(row => {
Array.from(row.children).forEach((cell, i) => {
cell.setAttribute('data-th', headers[i] || '');
});
});
});
});