Tips for emphasizing a table row according to its value

I am currently developing a Google web application that involves CRUD data generated from Google Sheets. The search function is working perfectly, but I am trying to enhance it by highlighting specific rows based on the data value in Column 7.

For example, if a row contains "PROCESSING" in Column 7, I want to highlight that row with an orange color to draw focus to that particular data.

Here are the script files I am using:

search.html

<table class="table table-hover">
      <thead>
        <tr>
          
          <th scope="col">Ref</th>
          <th scope="col">Vehicle</th>
          <th scope="col">Color</th>
          <th scope="col">Price</th>
          <th scope="col">Rent</th>
          <th scope="col">Location</th>
          <th scope="col">Status</th>
          <th scope="col">Send</th>
    
        </tr>
      </thead>
      <tbody id="searchResults">
    
       
      </tbody>
    </table>
    
    
    <template id="rowTemplate">
     <tr>
          
          <td class="L1"></td>
          <td class="L2"></td>
          <td class="L3"></td>
          <td class="L4"></td>
          <td class="L5"></td>
          <td class="L6"></td>
          <td class="L7"></td>
          <td class="L8"></td>
    
      </tr>
    </template>

main.html

  var searchResultsBox = document.getElementById("searchResults");
    var templateBox = document.getElementById("rowTemplate");
    var template = templateBox.content;
    
    searchResultsBox.innerHTML = "";
    
    resultsArray.forEach(function(r){
    
    var tr = template.cloneNode(true);
    var l1Column = tr.querySelector(".L1");
    var l2Column = tr.querySelector(".L2");
    var l3Column = tr.querySelector(".L3");
    var l4Column = tr.querySelector(".L4");
    var l5Column = tr.querySelector(".L5");
    var l6Column = tr.querySelector(".L6");
    var l7Column = tr.querySelector(".L7");
    var l8Column = tr.querySelector(".L8");
    
    l1Column.innerHTML = r[0];
    l2Column.innerHTML = r[1];
    l3Column.innerHTML = r[2];
    l4Column.innerHTML = r[3];
    l5Column.innerHTML = r[4];
    l6Column.innerHTML = r[5];
    l7Column.innerHTML = r[6];
    l8Column.innerHTML = r[7];
    
    searchResultsBox.appendChild(tr);
    
    });
    }

Is there a way to achieve this enhancement?

UPDATE I have been trying to implement a feature where certain rows are highlighted based on their values, but I need assistance in applying it to the existing code. Here is the script snippet for adding row colors based on values:

<!--Script to add row colour to the table based on value-->
<script type="text/javascript" 
src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.js"></script> 
<script type="text/javascript">  

$(document).ready(function(){
hightlightRows();
});

function hightlightRows(){
$('#table tr.in_out td').each(function(){
if ($(this).text() == 'RECEIVED') {
$(this).parent().css('background-color','#d4edda')
$(this).parent().css('color','#3d774b')
}
else if ($(this).text() == 'PROCESSING') {
$(this).parent().css('background-color','#FCD5D5')
$(this).parent().css('color','red')
}

else if ($(this).text() == 'SOLD') {

$(this).parent().css('color','#AEB6BF')
}

}); 
}

</script>

<!--END Script to add row colour to the table based on value-->

Answer №1

Is this what you're looking for? You can apply a class while the row is being processed and remove it once it's finished.


----Update----

I'm not sure how you determine when processing occurs, so I just randomly set an attribute in a column to indicate if it's currently processing (refer to the HTML code).

let result = document.getElementById("searchResults"); // get the result 
let rows = result.children; // all rows of the result
for (let row of rows) { // loop through each row
    for (let column of row.children) { // loop through each column within the row
        if (column.getAttribute("processing") === "true") { // check if any column has the attribute "processing"
            row.classList.add("processing"); // add a yellow background to the row
        }
    }
}
.processing {
    background-color: yellow;
}
<!DOCTYPE html>
<html>

<head>
    <title>Page Title</title>
</head>

<body>
    <table class="table table-hover">
        <thead>
            <tr>
                <th scope="col">Ref</th>
                <th scope="col">Vehicle</th>
                <th scope="col">Color</th>
                <th scope="col">Price</th>
                <th scope="col">Rent</th>
                <th scope="col">Location</th>
                <th scope="col">Status</th>
                <th scope="col">Send</th>

            </tr>
        </thead>
        <tbody id="searchResults">
            <tr>
                <td class="L1">L1</td>
                <td class="L2">L2</td>
                <td class="L3">L3</td>
                <td class="L4">L4</td>
                <td class="L5">L5</td>
                <td class="L6">L6</td>
                <td class="L7">L7</td>
                <td class="L8">L8</td>
            </tr>
            <tr>
                <td class="L1">L1</td>
                <td class="L2">L2</td>
                <td class="L3">L3</td>
                <td class="L4">L4</td>
                <td class="L5" processing="true">L5</td>
                <td class="L6">L6</td>
                <td class="L7">L7</td>
                <td class="L8">L8</td>
            </tr>
            <tr>
                <td class="L1">L1</td>
                <td class="L2">L2</td>
                <td class="L3">L3</td>
                <td class="L4">L4</td>
                <td class="L5">L5</td>
                <td class="L6">L6</td>
                <td class="L7">L7</td>
                <td class="L8" processing="true">L8</td>
            </tr>
        </tbody>
    </table>
</body>

</html>

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

Combining a pair of canvases

Currently, I am utilizing a JavaScript library to create a QR Code. This library generates the QR code by displaying it on a canvas. Nevertheless, my goal is to integrate a background behind this QR Code. I attempted to achieve this by first drawing the b ...

Instructions on adding an activity indicator in a centered box with a loader inside

I'm currently working on integrating an Activity Indicator into my Vue Native App, but I've been facing some issues as it doesn't seem to be displaying the Activity Indicator properly. Here is the code snippet I've tried: <Absolute ...

Need to specify the file type at the end of the URL for HTML input

How can I create a URL input form that requires the input to be a valid URL and end in a specific file type? Here is an example of my input: <input name="bg" placeholder="https://website.com/image" type="url"> Currently, the input field only restr ...

Confirm the validity of a data point within the JSON data package

When we send a request using the HTTP GET method, the API responds with the data. I need to ensure that the values of a specific input key match exactly what was specified in the GET URL. The URL that was used for the request: https://dummy.dns.com/Wells ...

React Native Header Icon Not Showing on the Left Side

I'm brand new to react and currently working on a project where navigation is done through a hamburger menu. I haven't encountered any errors in my code, but for some reason, the hamburger menu icon isn't displaying as expected. Interestingl ...

Sort through a JavaScript array based on an object that holds a limited number of the array's properties

Is there a way to efficiently find matching items in an array of objects using a filter object that only includes a subset of the array properties? For instance, consider a customer: let Customer = { Name: "John Doe", Age: 80, Hair: "Red", ...

PyScript <script type="py-editor"> Issue: SharedArrayBuffer cannot be used in an insecure environment

I am currently using PyScript to execute a basic Python script within my HTML file in order to show a pandas DataFrame. However, upon loading the page in the browser and attempting to run the code block by clicking the run button, I encounter an error rela ...

Execute a PHP task when the Jquery toggle button is activated, all without causing the page to redirect

I have implemented a toggle button in jQuery to display additional information. It is working well, but I am now trying to process some PHP tasks in the backend without having to redirect the page where the toggle resides. I have been struggling with thi ...

Analyze two sets of JSON data and compile a new JSON containing only the shared values

I am trying to generate two JSON arrays based on a shared property value from comparing two sets of JSON data. this.linkedParticipants =[ { "id": 3, "name": "Participant 2", "email": "<a href="/ ...

Is it possible to maintain the maximum height and width of a div across all levels of zoom?

In the process of developing a web application, I encountered an issue regarding setting the width and height of a div to a fixed number, regardless of the zoom level. While I was successful in changing the background color of the div across all zoom level ...

Clean coding techniques for toggling the visibility of elements in AngularJS

Hey everyone, I'm struggling with a common issue in my Angular projects: app.controller('indexController', function ($scope) { scope.hideWinkelContainer = true; scope.hideWinkelPaneel = true; scope.headerCart = false; scope. ...

A contact form overlaying a muted Google Maps view in an HTML website

Currently, I am in the process of developing a website that features a contact form. It would be great if I could incorporate Google Maps as a background, but with a greyed-out effect instead of a plain white page. After trying out a few solutions, I ende ...

Can you explain the purpose of the node_modules folder within AngularJS?

While exploring the AngularJS tutorial project, I came across the tutorial with a surprisingly hefty 60-megabyte node_modules directory. Does a simple clientside javascript project truly require such a large amount of unfamiliar data? I decided to delete ...

What is the method to retrieve the return value from this ajax request?

Here's a code snippet: var information = { ObtainInfo : function() { var url = 'http://www.bungie.net/api/reach/reachapijson.svc/game/info/'+storage.get('apikey'); $.ajax({ url: url, su ...

Is there a way to adjust the spacing between a specific background image in a design pattern? The image must be sourced online

I am currently working on creating a background pattern using only online images, and I need to adjust the spacing between them. Is there a way to specifically control the space between the images in the pattern using CSS? I know about the round and space ...

"Encountering difficulties with certain images not loading in the keyframe slide show feature on IOS

Ensure that the image in the slide show is preloaded, followed by preloading each additional image before transitioning to the next key frame. Finally, preload the original image for the final display. I even attempted changing the last image, but encounte ...

What's the issue with my jQuery AJAX script?

I am experiencing an issue with my ajax pages using jQuery to retrieve content. Only one page seems to be working properly, even though I have multiple pages set up. How can I resolve this problem? $(document).ready(function() { $('.lazy_content& ...

Adjust the color of the label when the checkbox is marked, and make it red when the checkbox is left

Looking to create a customized checkbox due to challenges in styling the default HTML checkbox, I have attempted the following code. The checkbox functions properly when clicking on the label, but I am unable to change the border color of the label based o ...

Applying a variety of class names in real-time based on JSON data results

Extracting multiple class names from a single key value in a JSON response and dynamically binding these class names. Here is an example of my JSON result: [ { "categoryId": 1, "categoryValue": "Mobiles", "divId": "MobilesId", "uiClass": ...

Setting up the php/MVC framework on a server

Currently, I have developed a project using HTML/PHP and need guidance on uploading it to the server. My knowledge of servers is limited, but I do understand that the first page should be an index.php or index.htm file placed in the public_html folder. How ...