Hide empty columns in table block

Wondering if anyone has tips for hiding an empty column in the Table Block? I’ve tried a few approaches including having the empty columns’ field values with a specific value for a javascript eventlistener to hide that .ag-cell but it didn’t work.


document.addEventListener('DOMContentLoaded', () => {
    const cells = document.querySelectorAll('.ag-cell');

    cells.forEach(cell => {
        if (cell.innerHTML.trim() === '' || cell.innerHTML.includes('<!--blank-->')) {
            cell.style.display = 'none'; // Hide the cell if it is empty or contains the placeholder