Styling Tables Dynamically With HTML, CSS, and JavaScript Based on Data

Although I've already searched for solutions, nothing seems to be working, so I'm reaching out again. My issue involves an HTML table:

<table class="table1">
        <tr>
            <th>Rank</th>
            <th>Name</th>
            <th>Picture</th>
            <th>Serial Number</th>
        </tr>
        <tbody class="tbody" >
            <tr class="bodyrow" ng-repeat="item in rank track by $index">
                <td>{{item}}</td>
                <td>{{name[$index]}}</td>
                <td> <img ng-src="{{img[$index]}}"/></td>
                <td>{{serialNumber[$index]}}</td>
            </tr>
        </tbody>

    </table>

The ranks can be categorized as Basic, Middle, or Advanced. If the rank is Basic, the row should appear blue. For Middle, yellow rows, and for Advanced, green rows. Can anyone offer assistance with this problem? Thank you.

Answer №1

To create a table with the rank name:

<table class="table1">
    <tr>
        <th>Rank</th>
        <th>Name</th>
        <th>Picture</th>
        <th>Serial Number</th>
    </tr>
    <tbody class="tbody" >
        <tr class="bodyrow" ng-class="item" ng-repeat="item in rank track by $index">
            <td>{{item}}</td>
            <td>{{name[$index]}}</td>
            <td> <img ng-src="{{img[$index]}}"/></td>
            <td>{{serialNumber[$index]}}</td>
        </tr>
    </tbody>

</table>

Applying styles:

.basic{background: blue}
.middle{background: yellow}
.advanced{background: green}

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

Ways to display a JSON object in CSV format

Is there a way to export a JSON object to a CSV file, where the sub-fields contain arrays of objects? I am unsure how to properly represent this embedded data in the CSV format. ...

What is the process for modifying the value of a concatenated string?

I have a scenario where I need to extract the date of a blog post from one page on a website and display it on another page within the same site. Initially, the date is shown as 2/22/18 on the first page. With the jQuery code provided below, I am able to ...

The link in the HTML code has been prevented from opening in a new

echo "<tr><th align='left'><a href=\"$email\">$name</a></th> I recently transformed a PHP Email App into a saving app. However, I am encountering an issue with opening links within the application. You ca ...

Customize jQuery Autocomplete choices depending on another jQuery Autocomplete input

I need to implement a feature where users can select a company and then an employee from that company. I came across a similar question on this link, but I specifically want both inputs to be autocomplete-enabled. This is the code snippet I currently have ...

Adjusting the size of content with CSS

I've been attempting to get an image to cover the entire screen on a device using CSS, but so far I haven't had any success. The image is within an :after pseudo element and content tag. Since it needs to be laid over the HTML, I can't use t ...

Replace the element's style using a JavaScript object

While there are numerous versions of this query, the existing answers fail to provide in-depth analysis. Query: How does this result in a height of 200 pixels? Consider the following code snippet: var el = document.querySelector('#r'); cons ...

HTML code featuring multiple dropdown menus, each equipped with its own toggleable textarea

I have multiple HTML drop downs, each triggering a textarea based on the selection. Currently, I'm using show and hide JavaScript functions for each question individually. Is there a way to streamline this so that I don't have to write separate c ...

Sharing data between AngularJS and D3 with JSON - a guide

When working on my application controller, I typically send a request to my API. This is what it usually looks like: .state('state1', { url: '/datas/:id', templateUrl: 'myurl.com', title: 'title', ...

What is the approach for incorporating JavaScript variables in Jade templates for writing inline CSS styles?

Struggling to inject CSS code dynamically? You're not alone. style(type='text/css') #header a#logo { background:url(constants.logo) no-repeat; } @media only screen and (-webkit-min-device-pixel-ratio: 1.5) { #header a#logo { ...

UI Router 10 causing $digest() loop with Angular 1.4.1 when $state.go is triggered during $stateChangeStart event

My application has a state that requires authorization. I have set up an event listener for $stateChangeStart, and if the toState.data.protected condition is met but the user is not authorized, I prevent default action using e.preventDefault() and redirect ...

Is it possible for Bootstrap 5 to extract data from an excel sheet and showcase it in an HTML table?

I have been scouring the depths of the internet with no success in finding a straightforward solution. I recently put together an HTML page that makes use of Bootstrap tables. Currently, my table contents are hardcoded directly into the HTML. I received a ...

Find the coordinate of a point in a three-dimensional space that lies at a given distance between two specified points

In order to achieve a smooth camera movement in three.js, it is essential to compute the position of point C. This calculation will ensure that the camera can smoothly transition from point A to a specific distance away at point B. ...

The excessive repetition in Angular flex layout is becoming overwhelming

I discovered and started using the responsive API provided by angular flex layout. While most of the time it works as intended, there are instances where I find myself duplicating directives in the code. Here's a simplified example: <div> &l ...

What are some ways to make the search bar on my website smaller in both length and width?

I have a WordPress website with the ivory search plugin installed for the search functionality. You can check out my website at www.osdoc.in. I am looking to make the search bar shorter and narrower as it is currently causing the menu icons to encroach on ...

successful callback after passport registration

router.post('/register', function(req, res, next){ var name = req.body.name; var email = req.body.email; var username = req.body.username; var password = req.body.password; var password2 ...

Arranging divs in a vertical layout using Bootstrap

After spending nearly 4 hours stuck on this, I have a question regarding my use of Bootstrap in building a mobile-friendly website with asp.net. I am new to bootstrap and trying to implement a collapsible menu functionality for mobile view. Currently, I ha ...

What is the correct location to store the bower.json file?

I'm currently using bower 1.2.2 to handle my client-side libraries for the first time with a new node app. I'm unsure whether I should initialize bower in the main project root alongside gruntfile.js and package.json, or within the static directo ...

Leveraging NextJS to perform server side rendering by injecting parameters from a caller component

I'm currently in the process of creating an application with a storefront using nextJS. I've successfully utilized getServerSideProps when loading a new page. This particular page is quite complex, as it consists of multiple components, each req ...

Preventing the (click) function from being activated during dragging in Angular 10

My div contains an openlayers map setup as shown below: <div id="map" (click)="getInfo($event)" class="map"></div> Whenever I drag my mouse to move around the map, the getInfo function is triggered. Is there a way to make it trigger only when ...

Grab the contents of the header while excluding specific attributes

CSS <div [@class="another class"]> <p> Different text <span> yet more text </span> </p> </div> Is there a way to create a selector in CSS to style the text inside p that is not within the child eleme ...