Tips for customizing the appearance of specific rows in Angular Material Data Table

Is there a way to apply specific styles to individual rows in a data table based on certain JSON values?

For instance, I want to color a row red if the temperature value is greater than 30, green if it's between 30 and 50, and else green.

Currently, I can only target even or odd rows using:

tr:nth-child(even)/tr:nth-child(odd)
.

Answer №1

To apply CSS classes directly to the row elements, you can do so by:

<tr mat-row *matRowDef="let row; columns: displayedColumns;"
    class="highlighted-row"
    [ngClass]="{'bold': row.value > 50}">
</tr>

After that, you have the flexibility to customize the styling of the rows using these classes:

.highlighted-row {
    color: blue;
}

.highlighted-row.bold {
    font-weight: bold;
}

Answer №2

My go-to method for styling table rows is using a specific code structure:

<tr *ngFor="let item of items"
                [ngClass]="{'highlight' : item.value == 10, 'accent' : item.value == 20, 'warn' : item.value == 30}">
              <td>{{item.value}}</td>
</tr>

To customize the appearance of these rows based on values, I utilize CSS classes like so:

.highlight{
   background-color: yellow;
}
.accent{
    background-color: lightblue;
}
.warn{
   background-color: red;
}

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

The Tailwind CSS file has been generated without any variables included

While utilizing Tailwind with a PostCSS configuration that generates a CSS file for production, only the necessary CSS classes are included in the file. However, upon inspecting the CSS file, I came across numerous empty CSS variables that seem unnecessary ...

What is the best way to determine if a child component's property has changed within a method?

The child component is app-google-maps-panel and has 2 properties in the parent component: <div class="col-6"> <app-google-maps-panel [longitude]="longitude" [latitude]="latitude"></app-google-maps-panel> & ...

Having issues with Jquery's ".fadeIn('slow')" function not properly loading the <tbody> element in Internet Explorer

I divided my table into two parts, <thead> and <tbody>. The <thead> is always displayed on the page, while the <tbody> is initially set to "display:none" and loads with content when a button is clicked. To load the <tbody>, I ...

Exploring the art of beautifying React.js with SCSS

I have been working on creating the homepage layout for a project using SCSS to style Reactjs with the assistance of an online course. However, I am facing an issue where my layout looks different from the one presented in the course even though I have app ...

The specified type of 'Observable<{ } | IProduct[]>' cannot be matched with the type of 'Observable<IProduct[]>'

Currently enrolled in the Angular 6 course by Deborah Kurata I have completed the Observables module, but encountered an error in my products.service. https://i.sstatic.net/zCzI0.png I came across this solution, but I have already tried it and believe i ...

Divs that are floated and only partially visible at the end

My layout consists of 6 Divs floated left to create 6 columns. The width of all these floats combined may extend beyond the window width for most users, especially with the 6th column included. Is there a way for this 6th column to be partially visible ( ...

What techniques can I use to achieve a seamless transition using Javascript and CSS?

I'm striving for a seamless CSS transition. The concept of transition had me puzzled. Even though I utilized the setTimeout method in JavaScript to make my CSS functional, it lacks that SMOOTH feel! Check out my code below. function slideChange( ...

Is it possible for me to tap into the component creation process within the Angular Router?

Inspiration struck me when I realized the potential of adding a directive to the component designed for this particular route. It would elevate the functionality by letting me convey crucial information in a more declarative manner. Despite learning that ...

When constructing a parameter, providers are unable to resolve another provider

I am currently working on an Ionic v3 app and I have encountered an issue with resolving providers within two other providers. Below is the error message I received: Uncaught Error: Can't resolve all parameters for DialogueMetier:([object Object], [ ...

The Material UI Grid item shifted upwards as a result of the image loading

While working on a project using the Material UI grid system with create-react-app, I encountered an issue with two adjacent grid items. Initially, they display as intended: https://i.sstatic.net/i9jeP.png However, upon loading the page, there is a brief ...

The mobile devices do not display minuscule text when rendering the React responsive UI

Recently, I decided to experiment with the responsive drawer feature of React Material UI. To try it out, you can access the online demo through the Code Sandbox link provided in the official documentation. To begin my testing, I copied and pasted the cod ...

Dropdown CSS navigation menu

I'm currently facing a challenge in designing a CSS menu. My goal is to have the menu open upwards instead of downwards, with the word "TEST" always staying at the top of the list even when the mouse hovers over it. I'm unsure of how to achieve t ...

Adjusting height in Google Maps to fill the remaining space

Currently, I am developing a map application where I want the Google Maps DIV to occupy the remaining height under the header. Here is the code snippet: <!DOCTYPE html> <head> <title>Map Application</title> <style type ...

Maintain the background color of the form select drop down even after clicking away from the form

I have customized a dropdown menu. <select name="country"> <option value="Andorra">Andorra</option> <option value="Albania">Albania</option> <option value="Armenia">Armenia</option> <opt ...

Having trouble with mobile support for Wordpress blockquotes?

Welcome. I am currently utilizing blockquote on my website, and it's functioning properly on desktop computers. However, there seems to be a significant issue when viewing it on mobile devices. https://i.sstatic.net/FMzVy.png Below are my current bl ...

Deployed on Azure: Correcting the Mime Type issue causing a blank css file to be sent to the server

While everything works perfectly fine locally, an issue arises when the application is deployed to Azure. The problem lies in loading the CSS file and an error message stating "Resource interpreted as Stylesheet but transferred with MIME type text/plain" i ...

Securing routes and layouts in the MEAN Stack framework

I am currently utilizing the MEAN Stack framework and have created 3 different layouts. I am looking to secure each layout route to prevent unauthorized access. const routes: Routes = [ { path: '', redirectTo: '/dashboard', ...

Launching a SpringBoot-Angular app on DigitalOcean

I have successfully set up a website on my local machine and now I am looking to deploy it to DigitalOcean. After creating a droplet and installing all the necessary components, I was able to access my angular application by entering the server's IP a ...

Is there a way to utilize Material UI React Grid, which incorporates CSS Flexbox, in order to achieve a specific grid layout where items are wrapped and evenly spaced?

Currently, in my React project, I am incorporating Material UI React. I am working with the <Grid> component to create a flexbox layout with 10 items. I am facing some difficulties in achieving a perfect grid layout with evenly spaced items. The lay ...

I am new to using RadList and I can't seem to get it to work properly. All I am seeing is a blank screen. Can anyone help me figure

When trying to utilize RadList for the first time, I am only met with a blank screen. What could be the issue here? I even attempted to insert the 'example' string in the label but encountered the same outcome "cats" represents a list containing ...