How to Filter, Sort, and Display Distinct Records in an HTML Table with jQuery, JavaScript, and

In the HTML page, there will be a total of 6 tabs labeled A, B, C, D, E, and F along with 2 dropdowns.

The expected behavior is as follows: The user will choose a value from the 2 dropdown menus. Based on the selected value, filtering should be applied to the HTML table in each tab.

var options = $("#comboB").html();
$("#comboA").change(function(e) {
    var text = $("#comboA :selected").text();
    alert(text);
    $("#comboB").html(options);
    $('#comboB :not([value^="' + text + '"])').remove();

});

$("#comboB").change(function(e) {
    var text = $("#comboB :selected").text();
    alert(text);
    var allRows = $("tr");
    allRows.hide();
    $("tr:contains('" + text + "')").show();

});
...
A B C D E F
A 2 B 1 C 2 D 1 E 1 F 1
Link to code I have attempted so far.

Here are a few challenges that need addressing:

1) When a value is selected from the dropdown, only columns corresponding to that value (e.g., selecting "F" shows only F columns) should be visible while displaying distinct values.

2) The change event is not triggered when the first value from the second dropdown is selected. How can this issue be resolved?

3) There is a requirement to create tabs for each option (A, B, C, etc.) and display columns based on the selected dropdown value. For instance, if "A" is chosen in the dropdown and the user switches to the "A" tab, only the A column should be displayed. Integrating navigation tabs with this functionality is necessary.

Answer №1

Feel free to test out this solution (Example)

var options = $("#comboB").html();
    $("#comboA").change(function(e) {
    var text = $("#comboA :selected").text();
    $("#comboB").html(options);
    $('#comboB :not([value^="' + text + '"])').remove();
    $("#comboB").prepend($('<option/>', { 'html':'Choose Value' }));
    $("table#Fdata tr").show().find('td').show();
});

$("#comboB").change(function(e) {
    if($(this).find('option:selected').text() == 'Choose Value') return;
    var text = $("#comboB :selected").text();
    $("table#Fdata tr").show().find('td').show();
    $("table#Fdata tr").not("tr:contains('" + text + "')").hide();
    $("table#Fdata tr:visible > td").not("tr td:contains('" + text + "')").hide();
});

This code snippet filters the display of tr elements based on selected values, considering that each row may contain multiple td cells with different contents.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

"Double the fun with fullcalendar.io - where every event is doubled

I am currently using a combination of rails and react.js for my latest project. Let's say I create event A, but then have a change of heart and decide to cancel it via a bootstrap modal. Afterward, I start another event B and proceed to confirm it, ho ...

The mobile responsive view in Chrome DevTools is displaying incorrect dimensions

Seeking some clarification on an issue I encountered: I recently created a simple webpage and attempted to make an element full width using width: 100vw. However, I observed that on screens smaller than around 300px, the element appeared smaller and not t ...

Is it possible to include multiple spyObjs within a beforeEach block?

In the process of testing an Angular 1 application using Jasmine, I have encountered a dilemma. My question is, can two spies be created for two different services within the same beforeEach statement? Currently, I have managed to make the first spy work ...

Removing a Child Object from a JSON Object in AngularJS

Encountering an error while attempting to remove a Child object Error Message: TypeError: ctrl.otsact.tests.splice is not a function HTML : <tr ng-repeat="act in ctrl.otsact.tests" ng-if="ctrl.editToggle"> <td><span ng-click="ctrl.r ...

Move the comment that is currently fixed to the top, following the old comments that have loaded above the

I’m working on a comments section where there is a fixed comment displayed at the top by default.. <button>Show All Comments</button> <ul class="comments"> <!--Ajax loaded hidden posts--> <li class="fixed">Fixe ...

Extract information from the table using $_POST

I possess a datatable within a form. Inside that table, there is a column designated for setting a price. Upon submitting the form on the same page, the $_POST data fails to populate. Consequently, I am in need of inserting it into the MySQL db post-submit ...

Various Mobile Devices Display Website in Unique Ways

I've been having trouble getting my website to display consistently across different phones and could use some assistance. You can view the site at www.fpphotos.store. I have set overflow-x:auto; for the table containing the images, with CSS styles de ...

Create artwork by drawing and adding text to an image before saving it

I am looking to enhance my website by adding a feature that allows users to draw on images hosted on the server. Additionally, I want users to have the ability to add text to the image and save their edits as a new picture. While it may seem like a simple ...

Deleting an element from an array stored in local storage with the help of jQuery

Summary: Developing a front-end wish list feature Tech Stack: Utilizing HTML5 (localStorage), CSS, and jQuery Key Features: Ability to add and delete items dynamically with real-time count display Challenge: Issue encountered when trying to remove added ...

Places & Their Accompanying Pictures

My website has a feature that allows users to save and add images for locations they have visited. The location details are stored in a MySQL database, while the image files are saved on my server in a folder with both original and thumbnail versions. I h ...

Tips for aligning the text of a button and placeholder vertically

I am facing an issue with centering placeholder/input text and button text vertically on my website. I used Bootstrap to create the site and utilized its input and button classes, but I couldn't figure out how to achieve vertical alignment. I tried ad ...

Using ReactJS to toggle a div upon clicking

I am facing an issue with toggling a div by clicking on text within a toggle bar. I am in the process of recreating a WordPress website template in React JS that was originally built using bootstrap. You can view the original template here. So far, I have ...

The substance (singular word) extends beyond the margins of the mobile screen

I am facing an issue on my webpage where the title is too long and it goes out of the page on mobile devices. Here is an example: <div class="module-head"><h3 class="module-head-title">Search Engine Optimization - Why Is It ...

What role does express play in the functioning of socket.io?

Forgive my lack of experience, but I am curious about the role of express in socket.io. Why is it necessary to require express when developing a chat application? Can we simply utilize the socket.io API for this purpose? Appreciate your help in advance. ...

When running through Selenium web driver, JS produces inaccurate results

Currently, I am utilizing JavaScript to determine the number of classes of a specific type. However, when I run the JS code in Webdriver, it provides me with an incorrect value. Surprisingly, when I execute the same JavaScript on the Firebug console, it gi ...

Is it possible to use basic HTML for creating views within the Express framework?

I recently began using node.js in conjunction with the Express framework, but I'm finding it challenging to remove Jade and other templates from my project. I prefer writing my views in plain HTML. Can anyone provide guidance on how to achieve this? ...

Text Box Driven Date Selection using Asp.Net's Date Picker Control

I have 2 text boxes that accept dates from a calendar control. One is for the "From" date and the other is for the "To" date. Here's how I would like the dates to be handled: For the first text box (From), it should only allow today's date or an ...

The Node.js application gracefully exited with code 0 with Forever

Running a Node.js Express app on CentOs 6.5 using the root account: root@vps [/home/test/node]# npm start app.js > <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="aedacbdddaee9e809e809f">[email protected]</a> s ...

avoiding less than or greater than symbols in JavaScript

I'm encountering an issue while attempting to escape certain code. Essentially, I need to escape "<" and ">" but have them display as "<" and "> in my #output div. At the moment, they show up as "&lt;" and "&gt;" on the page. This ...

Having trouble passing multiple associative array values from JavaScript/AJAX to PHP

We have been encountering an issue when trying to pass multiple associative array values from JavaScript/AJAX to PHP, as the PHP file is receiving an empty object/array. Could someone kindly assist us in retrieving the values of an associative array from ...