You are viewing limited content. For full access, please sign in.

Question

Question

Filter a table based off user selections, after lookup

asked on November 21, 2024 Show version history

Hello!

So first thing, I tried using AI to help create this code. It looks alright, but doesnt work at all.

 

I am trying to lookup data to fill a table, then filter that table based off what is selected on the form. Can anyone assist on why it is not working?

I believe I have all the CSS class's filled out properly. 

$(document).ready(function() {
    // Store selections
    var typeFunctionSelection = '';
    var sizeSelection = '';

    // Capture type function selection from text box
    $('.typeFunctionOption input').change(function() {
        typeFunctionSelection = $(this).val();
        applyFilter();
    });

    // Capture size selection (A3 vs A4) from radio buttons
    $('input[type=radio].sizeOption').change(function() {
        sizeSelection = $(this).val();
        applyFilter();
    });

    function applyFilter() {
        if (typeFunctionSelection && sizeSelection) {
            $('.deviceTable tr').each(function(index) {
                // Skip the header row
                if (index === 0) return;

                var row = $(this);
                var typeFunctionData = row.find('td.typeFunctionColumn').text();
                var sizeData = row.find('td.sizeColumn').text();

                // Include rows that match both selections or don't have a size listed
                if (typeFunctionData.includes(typeFunctionSelection) && (sizeData === sizeSelection || sizeData === '')) {
                    row.show();
                } else {
                    row.hide();
                }
            });
        }
    }
});

 

0 0

Answer

SELECTED ANSWER
replied on November 21, 2024

The script you posted did not use class, input and value correctly.

The following works for me:

$(document).ready(function() {
    // Store selections
    var typeFunctionSelection = '';
    var sizeSelection = '';

    // Capture type function selection from text box
    $('.typeFunctionOption input').change(function() {
        typeFunctionSelection = $(this).val();
        applyFilter();
    });

    // Capture size selection (A3 vs A4) from radio buttons
    $('.sizeOption input[type=radio]').change(function() {
        sizeSelection = $(this).val();
        applyFilter();
    });

    function applyFilter() {
        if (typeFunctionSelection && sizeSelection) {
            $('.deviceTable tr').each(function(index) {
                // Skip the header row
                if (index === 0) return;

                var row = $(this);
                var typeFunctionData = row.find('td.typeFunctionColumn input').val();
                var sizeData = row.find('td.sizeColumn input').val();

                // Include rows that match both selections or don't have a size listed
                if (typeFunctionData.includes(typeFunctionSelection) && (sizeData === sizeSelection || sizeData === '')) {
                    row.show();
                } else {
                    row.hide();
                }
            });
        }
    }
});

 

1 0
replied on November 22, 2024

This worked! Thank you so much!!

0 0

Replies

replied on November 21, 2024

I'm not sure if this is helpful at all, but I have something similar set up using lookup rules in the modern designer.

Essentially when an input, or multiple inputs, match the criteria in the table, it then fills in just the corresponding information and ignores everything else.

0 0
replied on November 22, 2024

I might be running an older version of LF that I do not have those options in my lookup rules. Thanks though!

0 0
replied on November 25, 2024

Totally fair! I should have added I'm on Cloud.

Glad you got it sorted out anyway! :)

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.