Dynamically Hide Table Columns based on "Grade" values in current view

Hi everyone,

I need some help with a JavaScript snippet to improve the UX of my production table.

Context: I have a table with 17 size columns (from PP to Inf 14). Each record belongs to a specific “Grade” (Adult, Extra 1, Extra 2, Unique, or Infantil).

The Challenge: I want to automatically hide the columns that are not relevant to the records currently being displayed in the table.

For example (as shown in the attached image): If the table is currently showing only records with Grade: Adult and Grade: Extra 1, I want the script to hide all columns related to Extra 2, Unique, and Infantil (3XGG, 4XGG, Tam. Unico, and Inf 02 through Inf 14).

Logic needed: The script should check all rendered records in the component. If a specific Grade category is NOT present in any of the rows, the corresponding columns for that category should be hidden (display: none) to keep the table clean and avoid horizontal scrolling.

Categories & Fields mapping:

  • Adulto: field_54, field_46, field_47, field_48, field_55

  • Extra 1: field_56, field_57

  • Extra 2: field_58, field_59

  • Unico: field_60

  • Infantil: field_61 through field_67

Has anyone implemented a “dynamic column visibility” logic that evaluates the records’ data like this?

Thanks in advance!

I managed to solve this using a different approach that turned out to be much cleaner for the UI and performance.

Instead of trying to dynamically hide specific columns in the Table Component (which can be buggy with pagination and different view modes), I decided to process the data using a Custom Server-side JavaScript Pipe.

The Strategy: I created a text field called Grade_Summary in my Items table. Whenever a record is saved, a Record Rule triggers this Pipe. The Pipe receives all size quantities and the “Grade Type” (Adult, Child, etc.) and returns a formatted string.

The “Hybrid” Logic: With the help of Gemini, we developed a script that ensures visual consistency:

  1. Standardized View: If the item is “Adult”, the script forces the display of the standard grid (PP, P, M, G, GG), even if the quantity is 0. This helps the warehouse team read the data in a consistent pattern.

  2. Fallback View: If the “Grade Type” is not recognized or is a custom mix, it falls back to showing only sizes with values greater than 0.

Here is the code I used in the Custom JavaScript Pipe (System Pipe):

(function() {
    // 1. Capture the Grade Type (e.g., "Adult", "Child") from your Record
    const gradeType = "{tipo_grade}"; 

    // 2. Map all your input parameters (Pipe Inputs)
    // Ensure these slugs match your Pipe Parameters exactly
    const values = {
        "PP": "{pp}", 
        "P": "{p}", 
        "M": "{m}", 
        "G": "{g}", 
        "GG": "{gg}",
        "XGG": "{xgg}", 
        "2XGG": "{extra2}", 
        "3XGG": "{extra3}", 
        "4XGG": "{extra4}", 
        "One Size": "{unico}",
        "Inf02": "{inf02}", 
        "Inf04": "{inf04}", 
        "Inf06": "{inf06}",
        "Inf08": "{inf08}", 
        "Inf10": "{inf10}", 
        "Inf12": "{inf12}", 
        "Inf14": "{inf14}"
    };

    // 3. Define the Fixed Groups
    // IMPORTANT: The keys here must match your Dropdown options in Tadabase exactly.
    const groups = {
        "Adulto": ["PP", "P", "M", "G", "GG"], // Always show these for Adults, even if 0
        "Infantil": ["Inf02", "Inf04", "Inf06", "Inf08", "Inf10", "Inf12", "Inf14"],
        "Extra 1": ["XGG", "2XGG"], 
        "Extra 2": ["3XGG", "4XGG"], 
        "Unico": ["One Size"]
    };

    let summary = [];
    
    // 4. Logic: Check if the Grade Type exists in our fixed groups
    if (groups[gradeType]) {
        // STANDARD MODE: Show all sizes in the group to maintain visual pattern
        const groupSizes = groups[gradeType];
        
        groupSizes.forEach(size => {
            const val = parseInt(values[size]) || 0;
            summary.push(size + ": " + val);
        });

    } else {
        // FALLBACK MODE: If Grade Type isn't found, show only non-zero values
        for (const [size, qty] of Object.entries(values)) {
            const val = parseInt(qty) || 0;
            if (val > 0) {
                summary.push(size + ": " + val);
            }
        }
    }

    // 5. Return the formatted string
    return {
        result: summary.length > 0 ? summary.join(' / ') : "No sizes selected"
    };
})();

Implementation: Then, I just mapped the pipe response result.result back to my Text Field using a standard Record Rule.

The result is a single clean column like “PP: 10 / P: 0 / M: 5 / G: 10 / GG: 0” instead of 17 columns full of empty zeros.

Hope this helps anyone trying to manage complex apparel grids!

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.