Am I using the correct method to parseInt within an if-else statement for Datatable?

Just started working with JS BS Datatables, wondering if this is the correct approach for using parseInt in an if else statement?

$(document).ready(function() {
    $('#myTable').DataTable({
        "order": [],
        "columnDefs": [{
            "targets": 'nosort',
            "orderable": false,
        }],
        
        
        "fnRowCallback": function(nRow, aData) {
            if (parseInt(aData[7].innerHTML,10) <= 30) {
                $('td', nRow).css('background-color', 'Red');
            } else if (aData[2] >= "30" && aData[2] < "50") {
                $('td', nRow).css('background-color', 'Green');
            }
        }
    });

});

As seen in my code, I'm attempting to convert the value of row aData[7] to an integer within the statement.

Answer №1

  "fnRowCallback": function(nRow, aData) {
                if (parseInt(aData[7], 10) <= 30) {
                    $('td', nRow).css('background-color', 'Red');
                } else if (parseInt(aData[7], 10) >= 31 && parseInt(aData[7], 10) <= 50) {
                    $('td', nRow).css('background-color', 'orange');
                }
            } else if (parseInt(aData[7], 10) >= 31 && parseInt(aData[7], 10) <= 50) {
                $('td', nRow).css('background-color', 'orange');
            }

Apologies to all for the inquiry, I have successfully resolved the issue.

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

Having trouble aligning modal to the left in Bootstrap 4 and MVC 5

I am currently working on a project where I am using a modal window to display an iframe. The webpage within the iframe is quite wide, so I have adjusted the width accordingly. However, the modal itself is situated in the center of the screen, causing the ...

Retrieve data from each URL listed in a JSON array using React

My json file structure was as follows: [ { "name": "google", "route": "/google", "url": "www.google.com" }, { "name": "bing", "route": " ...

The sidebar I designed didn't completely extend across the column in Bootstrap

My sidebar in Bootstrap didn't fill the entire column because I forgot to set a specific width for it. Here is the CSS code for my sidebar: .sidebar { position: fixed; /* top: 0; bottom: 0; left: ...

Unable to utilize the forEach() function on an array-like object

While I generally know how to use forEach, I recently encountered a situation that left me puzzled. Even after searching online, I couldn't find any new information that could help. I recently started delving into TypeScript due to my work with Angul ...

Issue with Bootstrap Carousel function in desktop browsers but functioning correctly on mobile devices

I'm experiencing issues with my bootstrap carousel on mobile browsers, but not on web browsers, despite trying various fixes and clearing my browser cache. Specifically, there is no sliding effect when clicking on the indicator, and everything else ap ...

Open the window by using the `Window.open` method, then find and

Is there a way to open a document, not in a new window but on the same page using JavaScript.Window.Open()? Could it be possible to display the document within a specific div element that is obtained with getElementById? For example: document.getElementB ...

What is the best way to call a method of a JavaScript object after calling a different method?

Upon frequently encountering this jQuery code snippet, I decided to simplify it into one level action as illustrated in the following code. function $(id) { var $ = document.getElementById(id); $.action1 = function() { }; return $; } Now ...

Remove dynamically created elements from an AngularJS div

Is there a way to remove an item from the criteria list when clicking the delete button? Currently, only the filter is being refreshed and not the tables. Any suggestions on how to resolve this issue? HTML <ul class="list-unstyled"> <l ...

switch from material ui lists on/off

Trying to learn React through coding, I've encountered an issue with displaying the 'StarBorder' icon next to folders when clicked. Currently, clicking on any folder displays the 'StarBorder' icon for all folders. Any tips on how t ...

Interactions with jQuery and the .load() method

Encountering a new issue with jQuery that I haven't seen before. Here's the code snippet: $(document).ready(function() { $('#browser_cat a').click( function() { $('#browser_cat').hide(); $('#browser_c ...

Saving HTML code entered in a textarea field does not work with the database

Recently, I encountered an issue on my website related to storing news posts in HTML format. My initial approach was to write the posts in HTML for better presentation and then transfer this code into a Textarea element. The plan was to save this input in ...

Having trouble running Javascript with jQuery's ajax load()?

I have encountered this problem and despite reading multiple posts, I am unable to find a solution. My challenge lies in loading an HTML file into a div that contains an unordered list. The list is supposed to function as an expanded menu with sub-items, ...

Leveraging Expressjs to act as a proxy for handling cross-origin requests made via AJAX

I'm working on a website that relies entirely on external APIs, without any server-side logic. All data will be retrieved from an external API. The backend server is mainly used for asset management and routing. We've decided to use nodejs with e ...

Issues with Promise execution sequence in ExpressJS Middleware

I need help creating an Express Middleware that checks if the user/password pair in the authorization header exists in a JSON file for educational purposes. I have integrated this middleware into a simple unit converter app. The issue I'm facing is t ...

Prevent the onClick event in the parent container div from triggering when clicking on a child element

Having trouble with event bubbling and onClick functions within a card element. The card has a heart icon that triggers an onClick function to unlike the card, but it also triggers the onClick function for the entire card which leads to a different page wi ...

Tips for effectively managing the timeout of server-side AJAX calls1. Maxim

I'm currently developing server code in ASP.NET with the MVC framework. The client-side code is written in javascript. When sending an AJAX request from the browser to the server, whether using JQuery or not, timeouts can be set. Additionally, the br ...

Storing form data in a file using React

I am trying to create a feature in my react component where instead of submitting a form and sending the data, I want to write this data to a file for later use. Is it achievable using vanilla JS or should I consider using a library? This is how my handl ...

Tips for efficiently storing and accessing data obtained from the "RESTBuilder" tool on the Total.js platform

After stumbling upon this informative tutorial on how to build a cryptocurrency comparison site with VueJs, I was inspired to create a single-page application using the total.js platform. My goal is to fetch the list of coins from the "coinmarketcap.com" A ...

What is the best way to incorporate lottiefiles for a loading animation on a Next.js project's landing

Is there a way to incorporate the use of lottie in a Next.js project (App Structure) in order to load an animated logo seamlessly? I attempted to include "use client" without success, and also tried importing Lottie from react-lottie as a dynamic import. ...

Tips on organizing SAPUI5 OData prior to binding it to a control on the client side

Suppose I have an OData list represented in JSON format: var data = [ {"category" : "A", "value" : 1, "group" : "x"}, {"category" : "B", "value" : 2, "group" : "y"}, {"category" : "C", "value" : 3, "group" : "x"}, {"category" : "A", "value" : 4, "grou ...