Change the color of certain rows in the table

I'm currently working on a project using Angular4 and ngx-datatable, so my .html file looks like this:

<ngx-datatable>
    <ngx-datatable-column>
        <ng-template> ...
         {{row.value}}

My goal is to check the value of each row - if it's greater than 100, I want to change the background color to red. Otherwise, it should remain white.

How can I achieve this? Any help would be greatly appreciated. Thanks!

Answer №1

One common method for swapping CSS classes based on conditions is shown below:

<ng-template [ngClass]="{highlighted: item.quantity >= 10, standard: item.quantity < 10}">

Make sure to specify the corresponding styles for both highlighted and standard classes in your CSS file.

Answer №2

Include the following in the row..

[style.background-color]='row.value >= 100 ? "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

Adjust the design of your Angular 2/5 app based on configuration file dynamically

I'm currently exploring the concept of a flexible layout that can be customized by users. Here's how it works: By default, there is a set layout of elements on the page (such as inputs, tables, etc). The user has the ability to rearrange where ...

What is the correct way to access and assign a value from a different getter or setter? I am facing an issue with the creation of my second array

Two http GET API calls are being made in the constructor. The first call is working fine and has a getter/setter to filter the main array (studentNameData) into a filtered array (filteredName). However, the second call is also trying to do the same thing b ...

What impact does the deprecation of TSLint have on Angular projects?

At the company I currently work for, we are on the cusp of embarking on a new Angular application project. Delving into the topic of linting, I came across news that TSLint is in the process of being deprecated. Given that TSLint is integrated into Angula ...

Utilizing a personalized directive within a ionic popup

I am currently using the ion-textarea autosize directive: import { Directive, HostListener, ElementRef } from '@angular/core'; @Directive({ selector: 'ion-textarea[autosize]' }) export class AutoResizeTextareaDirective { readonly ...

transform an array encoded in base64 format into a JSON object

I am encountering an issue where the base64 array I'm trying to send to an API is coming up empty. Here's a breakdown of what I'm doing: Firstly, I have an array of files with images in my code: [0: File {name: '766_generated.jpg' ...

Removing unnecessary files from a frontend npm package in a production environment: Best practices

Having trouble organizing the build process for my frontend web app created with Angular 2 and TypeScript. This is the structure I'm working with: / - dist/ <-- transpiled .js files - src/ <-- .ts files - assets/ - bower_components/ ...

Encountering "Unexpected token *" error when using Jest on an import statement

What could be the reason for Jest failing with the error message "Unexpected token *" when encountering a simple import statement? Error log: Admin@Admin-PC MINGW32 /d/project (master) $ npm run test > <a href="/cdn-cgi/l/email-protection" class="__ ...

"Dividing" a task stream/executer

Consider the following action type: interface SaveFoo { type: 'SAVE_FOO' payload: { id: string value: number } } I have a requirement to implement a saga that will apply throttling selectively. For instance, if the following actio ...

Struggling to get bcrypt.ts to install on Visual Studio Code for password hashing purposes

As part of my current project, I am working on creating a hash function following the guidelines provided by npmjs's bcrypt documentation: var bcrypt = require('bcrypt.ts'); // Synchronous - 10 rounds equal 10 hashes/sec const saltRounds = ...

What is the best way to work with the INITIAL_STATE injection token when it has dependencies

I have a dynamic module that loads lazily and uses ngrx/store with the feature StoreModule.forFeature('tasks', tasksReducer). To initialize this module, I need to set some initial values that are obtained through dependency injection from another ...

Looping through a set of arrays in Angular6 using *ngFor

Here is an example of an array: [[{"user":"1","nice":"0","sys":"1","CPU":"93","irq":"0"}, {"user":"1","nice":"0","sys":"1","CPU":"92","irq":"0"}, {"user":"1","nice":"0","sys":"1","CPU":"92","irq":"0"}, {"user":"1","nice":"0","sys":"1","CPU":"92","irq": ...

Creating a JSON utility type for an already existing type, such as JSON<SomeExistingType>

Is there any tool or utility available that can accomplish this task? const foo: Foo = { ... } const bar: string = JSON.stringify(foo) const baz: JSON<Foo> = JSON.parse(foo) JSON<Foo> would essentially mirror all the properties of Foo, with th ...

Setting up a variable with a changing value

In a very specific scenario, the body of type varies based on the length_type attribute (as illustrated in the example). enum LengthTypeEnum { SELECT = 'SELECT', STATIC = 'STATIC', CONDITION = 'CONDITION', PERIOD = ...

Developing an Observer and sending updates to my followers

I have a function that returns an Observer for subscription. Inside this function, I make an API call which also returns an Observer to which I subscribe. Once I analyze the data received from this Observer, I need to notify my own Observer subscribers. B ...

What is the reason behind hidden DOM elements appearing when I refresh the page?

When I refresh my webpage, I notice that the DOM elements I have hidden using ngIf are briefly visible before the actual state of my webpage loads. Why might this be happening? I am currently using Angular 8 version. <div *ngIf="!callInProgress ...

Add up values from a reducer using two distinct actions

I have implemented ngrx-store in my project and created a reducer that handles two different actions. Each action contains the number of task count as payload. Now, I want to sum up the numbers from both actions when they are emitted. When I dispatch thes ...

Issues with loading NextJS/Ant-design styles and JS bundles are causing delays in the staging environment

Hey there lovely folks, I'm in need of assistance with my NextJS and Ant-design application. The current issue is only occurring on the stagging & production environment, I am unable to replicate it locally, even by running: npm run dev or npm r ...

Discover a demonstration showcasing login and registration functionalities by utilizing Flask, SQLAlchemy, Angular, and JSON

Hello everyone, I am new to Flask, SQLAlchemy, Angular, and JSON. Despite being a beginner in these technologies, I am working on building an application that utilizes them. Can anyone kindly share a small demo of a login and registration page with me or ...

Response Looping Function

I am struggling with looping and storing data in an array. /** Model for displaying response*/ export class ResultsData { id: number, name: string, startDate: string, endDarte: string, startTime: string, ...

Transferring an Image from Angular 7 to Spring-boot

I've been attempting to transfer images from my Angular application to Spring Boot, but I'm encountering issues. When I send a POST request from Angular with the file, Spring Boot doesn't respond as expected. To investigate further, I tested ...