The filter on the mobile version is not displaying correctly

When I select a category in the input filter, only items with the same category are displayed when clicked. However, when I click on "Others" on the desktop version, only rows with that category are shown, but on mobile after resizing and filtering, nothing changes. All rows are still visible. I'm puzzled as to why there is a difference between the mobile and desktop versions when the JavaScript code is the same for both views.

highlightRows = () => {
    let oddRows = document.querySelectorAll('tbody > tr.show')
    oddRows.forEach((row, index)=> {
        if (index % 2 == 0) {
            row.style.background = '#f1f1f1'
        } else {
            row.style.background = '#fff'
        }
    })
}


const filterOptions = () => {
    const option = document.querySelector("#filter").value;
    const selection = option.replace('&', '')
  const rows = document.querySelectorAll("#body1 > tr");
  console.log(rows.length);
    
    rows.forEach(row => {
        let td = row.querySelector("td:last-child");
        let filter = td.innerText.replace('&', '');
        if (filter === selection) {
            row.className = 'show'
        } else {
            row.className = 'hidden'
    }

    });
    highlightRows()
};
document.getElementById("filter").addEventListener("change", filterOptions);
.table-filters {
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 2em;
  text-align: center;
}
.table-filters a {
  color: #222;
  font-size: 16px;
  font-weight: 500;
  margin-right: 1em;
  display: inline-block;
}
.table-filters a:hover {
  text-decoration: none;
}
.table-filters select {
  background: #fff;

  font-size: 16px;
  font-weight: 500;
  width: 12em;
  height: 2.5em;
}

table.stats {
  background: #fff;
  width: 100%;
  table-layout: fixed;
  border-radius: 6px;
}
tbody tr.show {
  display: table-row;
}
tbody tr.hidden {
 display: none;
}
table.vypis {
  border: 1px solid #ccc;
  border-collapse: collapse;
  margin: 0;
  padding: 0;
  width: 100%;
  table-layout: fixed;
}

table.vypis > caption {
  font-size: 1.5em;
  margin: .5em 0 .75em;
}

table.vypis > tr.vypis-riadok {
  background-color: #f8f8f8;
  border: 1px solid #ddd;
  padding: .35em;
}

table.vypis th,
table.vypis td {
  padding: .625em;
  text-align: center;
}

table.vypis th {
  font-size: .85em;
  letter-spacing: .1em;
  text-transform: uppercase;
}

@media screen and (max-width: 800px) {
  table.vypis {
    border: 0;
  }

  table.vypis > caption {
    font-size: 1.3em;
  }
  
  table.vypis > thead {
    border: none;
    clip: rect(0 0 0 0);
    height: 1px;
    margin: -1px;
    overflow: hidden;
    padding: 0;
    position: absolute;
    width: 1px;
  }
  
  table.vypis tr {
    border-bottom: 3px solid #ddd;
    display: block;
    margin-bottom: .625em;
  }
  
  table.vypis td {
    border-bottom: 1px solid #ddd;
    display: block;
    font-size: .8em;
    text-align: right;
  }
  
  table.vypis td::before {

    content: attr(data-label);
    float: left;
    font-weight: bold;
    text-transform: uppercase;
  }
  
  table.vypis td:last-child {
    border-bottom: 0;
  }
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="table-filters">
        <select id="filter">
          <option disabled selected value="none">Categories</option>
          <option>Hobby</option>
          <option>Others</option>

          
        </select>
      </div>
      <table class="vypis">
        <caption>Pohyby na účte</caption>
        <thead>
          <tr>
            <th scope="col">Refer</th>
            <th scope="col">Date</th>
            <th scope="col">Price</th>
            <th scope="col">Category</th>
          </tr>
        </thead>
        <tbody id="body1">
          <tr class="vypis-riadok">
            <td scope="row" data-label="refer">[[X04_riadok_1_popis_transakcie]] <br> [[X10_riadok_2_popis_transakcie]]</td>
            <td data-label="date">[[X02_riadok_1_datum]]</td>
            <td data-label="price">[[X08_riadok_1_suma]] €</td>
            <td data-label="category">Others</td>
          </tr> 
                    <tr class="vypis-riadok">
            <td scope="row" data-label="refer">[[X04_riadok_1_popis_transakcie]] <br> [[X10_riadok_2_popis_transakcie]]</td>
            <td data-label="date">[[X02_riadok_1_datum]]</td>
            <td data-label="price">[[X08_riadok_1_suma]] €</td>
            <td data-label="category">Hobby</td>
          </tr> 
                    <tr class="vypis-riadok">
            <td scope="row" data-label="refer">[[X04_riadok_1_popis_transakcie]] <br> [[X10_riadok_2_popis_transakcie]]</td>
            <td data-label="date">[[X02_riadok_1_datum]]</td>
            <td data-label="price">[[X08_riadok_1_suma]] €</td>
            <td data-label="category">Others</td>
          </tr>

Answer №1

Your code is functioning correctly, however, there is an issue with the rule display: block within the media query for the table.vypis tr selector. This particular rule is conflicting with another rule that hides the block. To resolve this, you should remove display: block from the table.vypis tr.

@media screen and (max-width: 800px) {

...
table.vypis tr {
    border-bottom: 3px solid #ddd;
    display: block;
    margin-bottom: .625em;
}
...

}

Alternatively, a second solution:

Add !important to the rule display: none within the tbody tr.hidden selector. The updated rule should be:

tbody tr.hidden {
 display: none!important;
}

I strongly recommend implementing the second solution!

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

Is there a way to invoke a function within an Angular Service from within the same service itself?

Below is the code snippet I am working with: angular.module('admin') .factory('gridService', ['$resource', 'gridSelectService', 'localStorageService', function ($resource, gridSelectService, ...

Creating Varied Results Depending on State Values

I'm in the process of developing a quiz system where different selections lead to distinct outcomes, but I'm facing an issue where the output remains the same. What might be causing this problem? As an example, a user chooses between button 1 an ...

In search of a fresh and modern Facebook node template

I've been on the hunt across the internet for a quality node.js Facebook template, but all I seem to stumble upon is this https://github.com/heroku/facebook-template-nodejs. It's okay, but it's built using express 2.4.6 and node 0.6.x. I wan ...

Custom JavaScript clock designed for the Lockscreen of jailbroken iPhones

I am struggling with getting my JavaScript code to display the time correctly on my HTML Lockscreen. After looking at a few examples, I noticed that others are using document.getElementById() instead of document.write() and pushing it to a div. I attempt ...

External elements - My physical being is in a state of chaos

Hello there, I hope everything is well with you. I have been working on creating a form using MaterializeCss to calculate an invoice for a craftsman. The user is required to input a number or select an item. Everything seems to be going smoothly so far. ...

Having trouble interacting with element - Selenium WebDriver is not allowing the click

I'm attempting to select the Checkout Button. This is what it looks like : https://i.stack.imgur.com/TiMEO.png And here's the HTML snippet for it : <div id="buy-button-next"> <span data-reactroot=""> <div data-cid="buy- ...

Error in RatingBar component: Vue.js 3 and Tailwind CSS not displaying dynamic width correctly

I have a component called RatingBar in Vue.js 3 with Tailwind CSS. My goal is to dynamically adjust the width of the parent element's class based on a value, but even though I see the desired width in DevTools, it always renders as 100%. Below is the ...

Exploring the power of Vue.js by utilizing nested components within single file components

I have been attempting to implement nested single file components, but it's not working as expected. Below is a snippet of my main.js file : import Vue from 'vue' import BootstrapVue from "bootstrap-vue" import App from './App.vue&apos ...

Is there a way to exclusively view references of a method override in a JS/TS derived class without any mentions of the base class method or other overrides in VS Code?

As I work in VS Code with TypeScript files, I am faced with a challenge regarding a base class and its derived classes. The base class contains a method called create(), which is overridden in one specific derived class. I need to identify all references ...

Having difficulty toggling checkboxes within a grid using the select all feature

In order to toggle checkboxes for a specific column within a grid, I encountered an issue within the JS "onUPCSelectAll" function with the eval statement displaying the following error message: JS runtime error: Object doesn't support property or meth ...

What steps are involved in developing an Angular library wrapper for a pre-existing Javascript library?

Imagine having a vanilla Javascript library that is commonly used on websites without any frameworks. How can you create an Angular library that can be easily installed via npm to seamlessly integrate the library into an Angular application? The process o ...

If the session is not set, direct to the login page after an Ajax request

In order to ensure that the $_SESSION is set on each page, I have included a 'check session' page. This means that the 'check session' script is also included on pages with AJAX/php functionality. For example: <?php require_once gl ...

unable to update the table due to issues with the knockout observableArray

My goal is to collect values from form fields and store them as an object in an observableArray. I want to display these objects in a table so that every time I hit the 'add' button, the table should be updated. However, I am facing issues with t ...

What is the most effective way to remove or modify an element in an array when a button is clicked?

I've hit a roadblock because I'm uncertain about how to access and remove elements stored within an array, especially if the user wants to delete from the middle. In this scenario, using pop won't suffice as it removes from the end without c ...

The ASP.NET MVC3 form collection registers as 0 when performing a jQuery ajax post

I'm currently developing a project on ASP.NET MVC3. My current challenge involves POSTing to a method that should return a set of data using the jQuery.ajax api. However, upon handling the request on the server, I noticed that the form collection&apo ...

Understanding Mongodb: the process of populating a schema that is referenced within another schema using an API

Looking to make adjustments to my Api in order to populate a referenced schema. Here's the schema I am working with: export const taskSchema = new Schema ({ user:{ type: String, required: true }, project: { type ...

Streamlined payment with PayPal Express Checkout via AJAX

I am working on integrating a JQuery client with PayPal's Express Checkout functionality for credit card transactions. The process involves the client presenting a form to the user, initiating a purchase via AJAX to the server, executing SetExpressChe ...

Even after applying trim() function, PHP's return statement still adds spaces unnecessarily

My function is supposed to return a boolean, but for some reason, it is adding spaces at the beginning of the string. Even after using trim(), the spaces persist. What could be causing this unexpected behavior? PHP function checkFile($v){ $result = is_ ...

Steps for updating a specific item within an object in an array of MongoDB document

Consider the following data collection, for which I have some questions: { "_id" : ObjectId("4faaba123412d654fe83hg876"), "user_id" : 123456, "total" : 100, "items" : [ { ...

iPad screen not displaying overflow for x and y axis

I'm encountering an issue with displaying the scrollbar on a div while using an iPad device. Currently, I am utilizing: -webkit-overflow-scrolling: touch; Although this is functioning properly, my goal is to have the scrollbar visible without the ...