Is there a way to emphasize specific tds within a row on my table?

I need assistance with highlighting specific table cells in Angular, rather than the entire row. Can someone provide guidance on how to achieve this?

Here is a snippet of my code:

 // ********** DATA TABLE ARRAYS **********//

  private beforeMonthsColumns: EditColumns[] = [
    { attribute: 'kagName', name: 'Erlöse / Kosten', object: null, disabledRanges: false },
    { attribute: 'kagNumber', name: 'KAG', object: null, disabledRanges: false }
  ];

  private monthColumns: EditColumns[] = [
    { attribute: '1', name: 'Jan', object: 'values', disabledRanges: true },
    ...
    { attribute: '12', name: 'Dez', object: 'values', disabledRanges: true }
  ];

  private afterMonthsColumns: EditColumns[] = [
    { attribute: 'currentYear', name: '', object: 'values', disabledRanges: true },
    { attribute: 'note', name: 'Anmerkung', object: null, disabledRanges: false },
  ];
 public rowHighlightStyleColor(formControl: FormControl) {
    return formControl.value ? this.changeColorService.defaultStyles.firstDesignFontColor : null;
  }

  public rowHighlightBackgroundColor(formControl: FormControl) {
    return formControl.value ?  this.changeColorService.defaultStyles.firstDesignBackgroundColor : null;
  }
private loadData() {
...
if (null !== data && data && yearlyBwaResults && yearlyBwaResults !== null) {
          this.mandantKagIds = data.map((d) => d.mandantKagId);
          const rows = [];
          const bwaMonthData: string[] = [];
          const bwaNames = _.uniq(data.map((d) => d.kagName)) as string[];
          for (const n of bwaNames) {
            bwaMonthData[n] = data.filter((d) => d.kagName === n);
            if (bwaMonthData[n].length > 0) {
              // console.log('bwaMonthData:', bwaMonthData[n][0]);
              const row: any = { kagName: bwaMonthData[n][0].kagName, kagNumber: bwaMonthData[n][0].kagNumber, values: {}, note: '' };
              const dbNrStr = `${bwaMonthData[n][0]['db-nr']}`;
              row['highlight'] = (dbNrStr.length === 7); // Here I highlighted the rows
              // console.log('row:', row);
              rows.push(row);
            }
          }
          this.data = rows;
        }
...
}

Answer №1

Implement the ngStyle directive in your HTML code to compare the row ID with a selected list and add a specific style if it matches. You can toggle the row ID by comparing it with a list of selected rows using functions like find(). The main idea is to assign a style to the row based on a certain condition.

<row [ngStyle]={ listOfSelected.find(item => item.id === row.id) ? 'classOnRow' : 'noStyle' }</row>

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

How can I access internal.Writable within the basic-ftp NodeJS module using TypeScript?

After examining the API documentation of the basic-ftp module, I came across the following: downloadTo(writableStream | localPath, remotePath, startAt = 0): Promise<FTPResponse> However, when utilizing the module in a TypeScript project, the method ...

Having trouble converting svg to png, thinking it might be due to discrepancies in svg elements

I am facing a puzzling issue where two different SVG elements are causing my JavaScript to work in one scenario but not the other. I have replaced the SVG elements in both examples, and surprisingly, only one works while the other does not. You can view th ...

Top Method for Connecting Numerous Dependent HTTP Requests Without the Need for Multiple Subscriptions and Iterations

I'm working on an angular project where I have an API that creates a line item and then loops through to call the API for each modification before firing the print request. Currently, I am using multiple subscribes for this process and I was wondering ...

Converting Javascript tools into Typescript

I'm currently in the process of migrating my Ionic1 project to Ionic2, and it's been quite an interesting journey so far! One challenge that I'm facing is how to transfer a lengthy list of utility functions written in JavaScript, like CmToFe ...

Incorporate a dynamic animation feature into the Morris Chart

I have successfully created a chart using Morris JS. However, the chart currently loads on the screen without any animation effect. I am interested in enhancing the visual appeal of the chart by adding an animation effect to it. Below is the script I am u ...

Resolving JavaScript ES6 module names

Forgive me if this is a silly question, but I am having trouble understanding how this particular line of code functions: import React from 'react'; My confusion lies in who and where exactly searches for the name 'react'? For instanc ...

Error: The React Hook "useX" should not be invoked at the top level of the code

I am facing a challenge while attempting to transfer the exception handling logic from the component to my service class: Login.tsx: import { useSnackbar } from "notistack"; // ... const Login = () => { const { enqueueSnackbar } = useSnack ...

status: 400 message: "There appears to be some issues with the validation process."

I'm encountering a 400 error code and I'm struggling to pinpoint the issue. My attempts to find solutions online have been unsuccessful so far. Any assistance or insight would be greatly appreciated. Thank you. The error message states: "The JSO ...

Collapse the nested child element within when the parent container is expanded/animated downwards

I'm trying to achieve a specific effect where, when the main parent div is toggled or slides down, the child div within it should also hide. Currently, I have a parent div that toggles to display a child div. When I click on a link within the child d ...

Rendering Local HTML with local styling and scripts in React Native Webview

I am having trouble loading a local HTML, CSS, and JS file in my React Native webview. The CSS is not being applied to the HTML. Here is my folder structure: https://i.sstatic.net/mqYT9.png My HTML file, along with CSS, images, and JS file are all placed ...

Please optimize this method to decrease its Cognitive Complexity from 21 to the maximum allowed limit of 15. What are some strategies for refactoring and simplifying the

How can I simplify this code to reduce its complexity? Sonarqube is flagging the error---> Refactor this method to reduce its Cognitive Complexity from 21 to the allowed 15. this.deviceDetails = this.data && {...this.data.deviceInfo} || {}; if (th ...

Can this be considered a sophisticated resolution?

Solving this issue is actually quite simple. Choose a name randomly from an array of names. Here is my approach: var names = [ 'nick', 'rock', 'danieel' ]; function randPicker(names) { var randNum = Math.floor((Math.rand ...

Leveraging ng-transclude and the require attribute for effective communication between directives

I'm working with two directives, let's call them: angular.module('app').directive('directiveX', directiveX); function directiveX(){ return { restrict: 'E', transclude: true, ...

The update operation for the Reference object encountered an error: The first argument includes a function within a

I'm encountering errors while attempting to create a simple cloud function that detects likes on the RD and then adds posts to a user's timeline. How can I resolve this issue? What mistake am I making? (The 2 errors below are from the Firebase ...

Encoding identification data from JSON using ColdFusion

Hello everyone, I've been puzzling over how to intercept and encrypt database record ID from a JSON request in ColdFusion. Below is the code I have so far, along with my unsuccessful attempt. Any assistance would be greatly appreciated. <cfquery ...

Enhance your 3D models with react-three-fiber's canvas modification capabilities

I am looking to modify the model function within the canvas. Currently, I have two separate Models (functions in js files) named Model1 and Model2. Both Models have the ability to outline the mesh when hovered over. The existing code structure is as follow ...

What is the best way to create a Typescript type consisting of only the public members of a different type?

Inside the realm of Typescript 4.3.5 In what manner can I establish a type that consists solely of the public members and properties of another type? Take into account: class Thing { public name: string private secret: string public greet(): string ...

Merge the xAxis functionality with Highcharts

My issue involves a chart generated by highcharts.js. The problem arises with a line chart consisting of 5 values (5 points), each displayed on the xAxis as follows: from value 1 to value 2: 0, 0.25, 0.5, 0.75, 1. I am looking to modify this display and re ...

Having trouble with executing functions on an express js Route?

I'm currently exploring Node and Express, and I'm encountering an issue when trying to pass a function instead of plain text on my route. It seems that the documentation only mentions using res.send() method with text. Even when attempting to use ...

Loading a Threejs model: "The CORS policy has blocked access to XMLHttpRequest from origin 'null' - How can I test this locally? Or should I simply upload it?"

Experimenting with three.js locally on a single HTML page, I am interested in exploring loading and manipulating 3D object files. Here is the code snippet that I am currently using: var loader = new THREE.AMFLoader(); loader.load( '. ...